Forum Moderators: not2easy
"clear: left"pushes Paragraph 2 down all the way below the floated div:
<html>
<body>
<div style="float: left; width: 4em">
abcd abcd abcd abcd abcd abcd abcd abcd
abcd abcd abcd abcd
</div>
<div id="main">
<p>Paragraph 1</p>
<p style="clear:left">Paragraph 2</p>
</div>
</body>
</html>
But then if i replace
<div id="main">by a
<fieldset>, Paragraph 2 stays to the right of the floated div. Same thing applies for tables. I've tested this in FF 2, IE 6, and Opera 9, using DTD HTML 4.01 Transitional.
So my question... Is this part of the standard, or an undocumented feature? And can i somehow make "clear"s inside divs behave the same way as inside fieldsets?
Thanks in advance
BUT it seems the validator accepts <fieldset> anywhere in a document, and it seems the DTD actually allows it to be used there as well...
Is the allowing of a fieldset anywhere an intentional feature or a bug? Hard to tell ...
Clear is defined here:
[w3.org...]
Now that one is clear (pun not intended): it'll clear everything floated earlier, provided it doesn't fall under the exception:
"The 'clear' property does not consider floats inside the element itself or in other block formatting contexts."
Block formatting context isn't something commonly quoted out here:
[w3.org...]
Note that table cells establish now block formatting contexts and that would indeed clarify why you see tables act the same.
But it doesn't mention a fieldset ...
Yet FF3, Opera and safari all agree on this ...
the clue why this is would be here:
In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch). This is true even in the presence of floats (although a box's line boxes may shrink due to the floats), unless the box establishes a new block formatting context (in which case the box itself may become narrower due to the floats).
fieldsets have by default a border around them and that border would go under the float (becoming invisible if it didn't establish a new block formatting context ...)
Now armed with this, can we make a div behave like the fieldset appears to do?
sure:
style="display:inline-block"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>untitled</title>
</head>
<body>
<div style="float: left; width: 4em">
abcd abcd abcd abcd abcd abcd abcd abcd
abcd abcd abcd abcd
</div>
<div>
<p>Paragraph 1</p>
<p style="clear:left">Paragraph 2</p>
</div>
</body>
</html>