Previous Message
Next Message

Floats *require* widths (wiki says so)??

Sent by Arlen Walker on 2 September 2003 17:05


On Tuesday, September 2, 2003, at 08:50  AM, [EMAIL-REMOVED] 
wrote:

> This was pointed out to say that it is invalid to float an element to 
> get
> it to 'shrinkwrap'. Browser quirks aside, I've never read that it is
> required to have a float + width. In fact I don't see that in the
> following section in the CSS documentation (the W3's examples don't even
> have widths):
>
> http://www.w3.org/TR/REC-CSS1#floating-elements
>
> http://www.w3.org/TR/REC-CSS1#float
>
> Am I missing crucial documentation somewhere? Why is it stated in the 
> wiki
> floats must always have a width (regardless of browser)?

Try here: http://www.w3.org/TR/REC-CSS2/visuren.html

Section 9.5: "A floated box must have an explicit width (assigned via 
the 'width' property, or its intrinsic width in the case of replaced 
elements)."

I didn't check the page in the wiki, but the reason you can't 
"shrink-wrap" lies in section 4.1.2 of the CSS1 spec:

"By default, the 'width' of an element is 'auto'. If the element is not 
a replaced element, this means that the 'width' is calculated by the UA 
so that the sum of the seven properties mentioned above is equal to the 
parent width. If the element is a replaced element, a value of 'auto' 
for 'width' is automatically replaced by the element's intrinsic width."

What this means is that unless the element is a replaced element (such 
as 'img', which is the element the W3C uses in their examples) then the 
width of the element is adjusted to be such that padding + border + 
margin (left and right values) + width is 100% of the width of the 
parent. Hence if you create a single-word text block and float it 
without specifying a width, then the user agent *should* expand the 
block to 100%. Not all do, but IE5/Mac is particularly bloody-minded 
about it.

If the element is a replaced element, then the width is the width of the 
element.

This has lead to the "received wisdom" of always specifying a width for 
floats as the only way to get past this particular impass.

Have fun,
Arlen

-----
In God We Trust, all others must supply data

______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread:

Possibly related: