Re: % width floats within absolute positioned element

Simon Pieters <zcorpan@hotmail.com> wrote on Sun, 10 Dec 2006:

> What is correct rendering for these test cases?
> 
>    <!doctype html>
>    <title>001</title>
>    <style>
>     div { position:absolute; background:yellow; }
>     p { float:left; width:50%; background:blue; color:white; }
>    </style>
>    <div>
>     <p>What should happen here?</p>
>    </div>
> 
>    <!doctype html>
>    <title>002</title>
>    <style>
>     div { position:absolute; background:yellow; }
>     p { float:left; width:50%; background:blue; color:white; }
>     span { float:right; }
>    </style>
>    <div>
>     <p>What should happen here?</p>
>     <span></span>
>    </div>

It is true that browsers don't agree, but I believe the spec is not
ambiguous.

I'd say, for the first example:

The absolutely positioned div's width is "shrink-to-fit" by 10.3.7.

The p's width is specified as '50%', but its containing block (the div)
has no a-priori width, so the width is explicitly undefined (section
10.2). One obvious possibility is to use shrink-to-fit. [Browsers
indeed seem to do this.]

Whatever the p ends up as, the div should "shrink-to-fit" to the same
size, per 10.3.7. [Browsers vary wildly on the width of the div :-( ]

The second example looks exactly the same, because the floating span has
zero width (by 10.3.5) and thus fits next to the p, without changing
the width of the div.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Wednesday, 21 February 2007 15:47:09 UTC