Forum Moderators: not2easy

Message Too Old, No Replies

Clearing the float

         

Fotiman

9:11 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a bunch of form controls like this:

<fieldset>
<legend>Set1</legend>
<label id="L1">Item1<input></label>
<label id="L2">Item2<input></label>
<label id="L3">Item3<input></label>
<label id="L4">Item4<input></label>
</fieldset>

I'm using the following styles to float each of the inputs:


fieldset
{
display: block;
margin: 0 0 1.5em 0;
padding: .5em;
}
label
{
display: block;
float: left;
margin: 1em 1em 0 0;
}
label input
{
display: block;
width: 15em;
}

Which gives me something like this:


` = padding
. = margin
, = whitespace
+-- Set1 --------------------------------+
¦````````````````````````````````````````¦
¦`......................................`¦
¦`+----------------+.+----------------+.`¦
¦`¦Item1,,,,,,,,,,,¦.¦Item2,,,,,,,,,,,¦.`¦
¦`¦[______________]¦.¦[______________]¦.`¦
¦`+----------------+.+----------------+.`¦
¦`......................................`¦
¦`+----------------+.+----------------+.`¦
¦`¦Item3,,,,,,,,,,,¦.¦Item4,,,,,,,,,,,¦.`¦
¦`¦[______________]¦.¦[______________]¦.`¦
¦`+----------------+.+----------------+.`¦
¦````````````````````````````````````````¦
+----------------------------------------+

Now, suppose I want the 2nd item to clear the first, giving me something that looks visually like this:


` = padding
. = margin
, = whitespace
+-- Set1 --------------------------------+
¦````````````````````````````````````````¦
¦`...................,,,,,,,,,,,,,,,,,,,`¦
¦`+----------------+.,,,,,,,,,,,,,,,,,,,`¦
¦`¦Item1,,,,,,,,,,,¦.,,,,,,,,,,,,,,,,,,,`¦
¦`¦[______________]¦.,,,,,,,,,,,,,,,,,,,`¦
¦`+----------------+.,,,,,,,,,,,,,,,,,,,`¦
¦`......................................`¦
¦`+----------------+.+----------------+.`¦
¦`¦Item2,,,,,,,,,,,¦.¦Item3,,,,,,,,,,,¦.`¦
¦`¦[______________]¦.¦[______________]¦.`¦
¦`+----------------+.+----------------+.`¦
¦`...................,,,,,,,,,,,,,,,,,,,`¦
¦`+----------------+.,,,,,,,,,,,,,,,,,,,`¦
¦`¦Item4,,,,,,,,,,,¦.,,,,,,,,,,,,,,,,,,,`¦
¦`¦[______________]¦.,,,,,,,,,,,,,,,,,,,`¦
¦`+----------------+.,,,,,,,,,,,,,,,,,,,`¦
¦`...................,,,,,,,,,,,,,,,,,,,`¦
¦````````````````````````````````````````¦
+----------------------------------------+

I would expect that I could simply add the following rule:


#L2 { clear: left; }

In Firefox, this works as I would expect. But in IE, the next item is still getting floated to the right of Item1 instead of Item 2. So my output looks like this:


` = padding
. = margin
, = whitespace
+-- Set1 --------------------------------+
¦````````````````````````````````````````¦
¦`......................................`¦
¦`+----------------+.+----------------+.`¦
¦`¦Item1,,,,,,,,,,,¦.¦Item3,,,,,,,,,,,¦.`¦
¦`¦[______________]¦.¦[______________]¦.`¦
¦`+----------------+.+----------------+.`¦
¦`......................................`¦
¦`+----------------+.+----------------+.`¦
¦`¦Item2,,,,,,,,,,,¦.¦Item4,,,,,,,,,,,¦.`¦
¦`¦[______________]¦.¦[______________]¦.`¦
¦`+----------------+.+----------------+.`¦
¦````````````````````````````````````````¦
+----------------------------------------+

Any ideas how I can get IE to play nice? Here's the complete HTML and CSS:



<!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:utf-8">
<title></title>
<style type="text/css">
fieldset
{
display: block;
margin: 0 0 1.5em 0;
padding: .5em;
}
label
{
display: block;
float: left;
margin: 1em 1em 0 0;
}
label input
{
display: block;
width: 15em;
}
#L2 { clear: left; }
</style>
</head>
<body>
<div id="container">
<fieldset>
<legend>Set1</legend>
<label id="L1">Item1<input></label>
<label id="L2">Item2<input></label>
<label id="L3">Item3<input></label>
<label id="L4">Item4<input></label>
</fieldset>
</div>
</body>
</html>

DrDoc

10:15 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think there is a way of solving this, unfortunately.

Not without changing the markup:

...
<label id="L1">Item1<input></label>
<div style="clear: left;"></div>
<label id="L2">Item2<input></label>
...

Fotiman

10:30 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you know why that is? Why does IE not clear the float? It's obviously a bug in IE... is it a documented bug?

DrDoc

10:34 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps a misinterpretation of the float rules?
[w3.org...]

Reading the "precise rules" I get confused too :)

jessejump

10:47 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



>>>>> suppose I want the 2nd item to clear the first,

Don't float the first.