Afficher un message
Vieux 18/03/2008, 15h08   #8
Ben C
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: is <div style="display: inline"> identical to <span>?

On 2008-03-18, Summercool <Summercoolness@gmail.com> wrote:
> On Mar 18, 1:19 am, Ben C <spams...@spam.eggs> wrote:
>
>> They can look different in theory.
>>
>> In HTML 4, span can only contain members of the %inline group. So
>>
>> <span><div>hello</div></span>
>>
>> is invalid. The browser can do what it wants with it. For example it
>> might close the span before the div and reopen it after it. This would
>> mean that if you'd set span { color: red } for example, "hello" wouldn't
>> get it.
>>
>> Having said that I haven't met a browser that doesn't just allow div
>> nested inside span as if there were nothing wrong with it.
>>
>> <div style="display: inline"><div>hello</div></div>
>>
>> is valid and should always do what you expect.

>
>
> I am only guessing... since inline element cannot contain any block
> element, it doesn't matter whether it is
>
> <span><div>hello</div></span>
>
> or
>
> <div style="display: inline"><div>hello</div></div>
>
> Both of them are considered invalid the same way. (since they are
> inline element containing a block element)


No, that's the point.

Something that's display: inline can contain something that's display:
block. That's not invalid, and it is completely specified by CSS 2.1
what's supposed to happen (you'll get anonymous blocks either side of
the block).

CSS doesn't impose any requirements about what you can nest inside what.
Anything goes (although some properties may not apply in particular
situations).

But <span> cannot contain <div> according to HTML rules (the HTML DTD is
full of requirements about what you can nest inside what) and <div> can
contain <div>, regardless of what you've set display to.

<span><div>hello</div></span>

is invalid HTML but

<div style="display: inline"><div>hello</div></div>

is valid HTML, and correct CSS with defined behaviour. There is
absolutely nothing wrong with it (although it's rather odd style).
  Réponse avec citation
 
Page generated in 0,06195 seconds with 9 queries