Last Float adds parent's top padding to float's bottm margin in IE6-7

Hi,
I have a basic footer div with 10px padding on top and bottom. Within that I have a floated ul to contain it’s floated “li” and “a”. After that I have a floated and cleared form (preferably with no width set).

After those two elements I have a standard “p” tag that has clear both hooked to it also. Not a problem so far, all is well in FF, Opera, Safari, and IE8.

I am aware of the fact that it is best to set a bottom margin on a float rather than a top margin on a non floated & cleared element (my “p” tag).

Here is what I have

I have found a couple of workarounds for IE6/7 but I am curious to know what is going on. They are taking the 10px top padding of the footer div and adding it to the 10px bottom margin of the floated form (20px total under the form).

I can fix it by removing the float from the form and setting a width (prefer not to but it would work)

I could also fix it by removing the top padding from the footer and set a top margin on my first floated element (the ul).


Just ran a quick test with a regular div instead of a form and the form element has nothing to do with it, shown below. Why is IE 6-7 adding the parent top padding to the last floats bottom margin? :eye:

Maybe I should not ask why but rather “is this a bug I am unaware of”?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Footer Form</title>

<style type="text/css">

a {text-decoration: none; }

body {
    margin:0;
    padding:0;
    background: #fff;
    font-size:100%;
}

/*=== Footer styles ===*/
[B]#footer[/B] {
    width:870px;/*900px; total*/
    [COLOR=Blue]padding:10px 15px 10px;/*IE6/7 add the top padding to the bottom margin of the floated foodiv*/[/COLOR]
    margin:20px auto;
    overflow:hidden;/*contain footer floats*/
    background:lime;
}
/*=== UL styles ===*/
[B]ul#footnav[/B] {
    [COLOR=Blue]float:left;[/COLOR] background:#000;
    [COLOR=Blue]margin:0 0 10px 0;[/COLOR]
    padding:0;  
    font: .7em Arial, Helvetica, sans-serif;
    text-transform: uppercase;
    color: #FFF;
}
#footnav li{
    float:left;
    list-style:none;
    margin:0 0 0 8px; 
}
#footnav li.first {margin:0;}

#footnav li a{
    float:left;
    padding:0 8px 0 0;
    text-decoration:none;
    color:#FFF;
}
#footnav li a:hover {color:#5BAC7E;text-decoration:underline;}

/*=== float & clear div ===*/
[B]#foodiv[/B]{
    [COLOR=Blue]float:left; 
    clear:left;[/COLOR]
    background:red;
    [COLOR=Blue]margin-bottom:10px;[/COLOR]
}

[B]p#copyright[/B] {
    [COLOR=Blue]clear:both;[/COLOR]
    [COLOR=Blue]margin:0;[/COLOR]
    color: #DBD5C5;
    font:.65em Georgia, "Times New Roman", Times, serif;
    background:#000;
}
</style>

</head>
<body>

<div id="footer">
    <ul id="footnav">
        <li class="first"><a href="#">terms of use</a>|</li>
        <li><a href="#">privacy policy</a>|</li>
        <li><a href="#">support</a>|</li>
        <li><a href="#">register</a>|</li>
        <li><a href="#">contact</a></li>
    </ul>
    
    <div id="foodiv">
        <p>Blah Blah Blah Blah Blah Blah Blah Blah Blah</p>
        <p>Blah Blah Blah Blah Blah Blah Blah Blah Blah</p>
    </div>
    
    <p id="copyright">Copyright &copy; 2009 Market Lions Digest. All Rights Reserved. Joomla! is Free Software released under the GNU/GPL License.</p>
</div>

</body>
</html>

Hi Ray, I seem to notice it slightly different.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<base href="http://www.css-lab.com/test/form-test.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Footer Form</title>

<style type="text/css">

a {text-decoration: none; }

body {
    margin:0;
    padding:0;
    background: #fff;
    font-size:100&#37;;
}

/*=== Footer styles ===*/
#footer {
    width:870px;/*900px; total*/
    margin:0px auto;
    overflow:hidden;/*contain footer floats*/
    background:lime;
}
ul#footnav {
     background:#000;
    margin:0 0 10px 0;
zoom:1;
    padding:0;  
	font: .7em Arial, Helvetica, sans-serif;
	text-transform: uppercase;
	color: #FFF;
}
#footnav li{
    list-style:none;
    margin:0 0 0 8px; 
display:inline;
}
#footnav li.first {margin:0;}

#footnav li a{
    float:left;
    padding:0 8px 0 0;
    text-decoration:none;
    color:#FFF;
}
#footnav li a:hover {color:#5BAC7E;text-decoration:underline;}

p#copyright {
    clear:both;
    margin:0;
	color: #DBD5C5;
	font:.65em Georgia, "Times New Roman", Times, serif;
	background:#000;
}

/*=== Footer form styles ===*/
#footform {
    /*width:41em;/*IE6/7 is ok with width and no float*/
    float:left;/*IE6/7 adds footer top padding when float is used*/
    clear:left;
    margin:0 0 10px; 
    padding:5px 5px 5px 0;
    background:red;
	vertical-align:baseline;
	font:.6em Verdana, Geneva, Arial, Helvetica, sans-serif;
}
#footform .lt-label {
    display:inline-block;/*set a width*/
    width:6.3em;
    padding:2px;
    text-align:right;
    color:#999;
    background:#000;
}
/* html #footform .lt-label{display:inline;}/*IE6 inline-block trigger*/
/*+html #footform .lt-label{display:inline;}/*IE7 inline-block trigger*/

#footform .label {
    margin:0 5px 0 0;
	color:#999; background:#000;
}
.mid,.button {vertical-align:middle;}

#footform .box {
    margin:0 5px 0 0;
	color:#999; 
}
#footform .button {
	padding:1px;
	margin:0 5px;
}
#footform a{
    margin:0 5px 0 0;
	color:#EEE;
    background:#000;
}
#footform a:hover{
    text-decoration: none;
}
</style>

</head>
<body>

<div id="footer">
    <ul id="footnav">
        <li class="first"><a href="#">terms of use</a>|</li>
        <li><a href="#">privacy policy</a>|</li>
        <li><a href="#">support</a>|</li>
        <li><a href="#">register</a>|</li>
        <li><a href="#">contact</a></li>
    </ul>
    <form id="footform" action="#" method="post" name="footform">
        <label class="lt-label" for="username">Username</label> 
        <input class="box" id="username" type="text" name="username" size="15" alt="username" 

onclick="login.username.value='';"/>        
        
        <label class="label" for="remember">Remember Me</label>        
        <input class="box mid" id="remember"type="radio" name="remember" value="yes" alt="Remember 

Me"/>       
        <input class="button" type="submit" name="Submit" value="Login"/>        
        
        <br />        
        <label class="lt-label" for="passwd">Password</label>
        <input class="box" id="passwd" type="password" name="passwd" size="15" alt="password" 

onclick="login.passwd.value='';"/>        
        
        <a href="#">Not a member?</a>       
        <a href="#">Register Here</a>
        
        <input type="hidden" name="option" value="#"/>            
        <input type="hidden" name="task" value="#"/>            
        <input type="hidden" name="return" value="#"/>            
        <input type="hidden" name="#" value="#"/>
    </form>
    <p id="copyright">Copyright &copy; 2009 Market Lions Digest. All Rights Reserved. Joomla! is 

Free Software released under the GNU/GPL License.</p>
</div>

</body>
</html>

The parent has no paddin/vertical marins.
However, on the #footnav if I remoe the bottom martin then it is fixed.

Also, setting the footer to display:inline-block also fixes it (haslayout probably since I didn’t do the display:inline for it first)

A hard clearing element (caught myself ;)) also works

<b style="height:0;display:block;font-size:0;clear:both;"></b>
    <p id="copyright">Copyright &copy; 2009 Market Lions Digest. All Rights Reserved. Joomla! is 

Free Software released under the GNU/GPL License.</p>

I must admit I have never seen this bug before, even scoured my personal own little database of bugs I have been collecting over the few years and I have never run across it.

I have something simliar and this is a permutation of that bug probably (same fixes I told above)

It jiust seems to be a haslayout bug triggered by the footer not having haslayout

It jiust seems to be a haslayout bug triggered by the footer not having haslayout
My footer had “layout” with a width set, maybe you meant the ul. But it had “layout” also with the float.

I see you pulled the float off my ul and set zoom instead. If you look back at my posted code you will see that I do have “layout” everywhere.

The parent has no paddin/vertical marins.
Yes I mentioned that no top padding on the parent would fix it. It is that top padding that plays a role in the bug.

Yes, I had a 20px top margin on the #footer just for this test case but it does not seem to have anything to do with the bug

A hard clearing element (caught myself ;)) also works
I’ll pass on that one. :wink:
I have found a workaround, I just don’t remember this bug. My thread title describes it.

Sorry I meant the actual footer (which I define as the copyright/anything like that lol :))

p#copyright {
    clear:both;
    margin:0;
    color: #DBD5C5;
    font:.65em Georgia, "Times New Roman", Times, serif;
    background:#000;
}

Here is a reduced test case of the bug in action. :wink:
http://www.css-lab.com/bug-test/ie-last-float.html

I set a 50px top padding on the parent and you will see that it is added to the 10px bottom margin of the last float. 60px between the last float and the cleared “p”.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Parent top padding added to the bottom margin of the last float</title>
<style type="text/css">
body {
    margin:0;
    padding:0;
    background: #fff;
    font-size:100%;
}
h2 {text-align:center;}

#wrap {
    width:870px;/*900px; total*/
    padding:50px 15px 10px;/*IE6/7 add the top padding to the bottom margin of the last float*/
    margin:0 auto;
    overflow:hidden;/*contain floats*/
    background:lime;
}
.foodiv{
    float:left; 
    clear:left;
    background:yellow;
    margin-bottom:10px;
}
p{margin:0;}

p.clear{
    clear:both;
    color:#FFF;
    background:#000;
}
</style>

</head>
<body>
<h2>Parent's top padding added to the bottom margin of the last float in IE 6-7</h2>
<div id="wrap">  
    <div class="foodiv">
        <p>Blah Blah Blah Blah Blah Blah Blah Blah Blah</p>
    </div>
    <div class="foodiv">
        <p>Blah Blah Blah Blah Blah Blah Blah Blah Blah</p>
    </div>
    <div class="foodiv">
        <p>Blah Blah Blah Blah Blah Blah Blah Blah Blah</p>
    </div>
    <div class="foodiv">
        <p>IE6/7 add the parent's top padding to the bottom margin of this last float.</p>
    </div>    
    <p class="clear">This is a cleared paragrapgh with no margins</p>
</div>
</body>
</html>

Ahh, I see what you are saying now. :wink:

I can trip haslayout just by setting inline-block on that cleared p tag.

Working from the test case I just posted above this will fix IE6/7

Thanks for pointing that out Ryan

[B]p.clear[/B]{
    [COLOR=Blue]display:inline-block;[/COLOR]
    clear:both;
    color:#FFF;
    background:#000;
}

One more question about The Form Structure.

IE6 is not giving the proper width to the “password” input box.

IE7 shows it correctly as all other browsers do. Both of my input boxes are set to size=“15”.

[B]<br />[/B]        
        <label class="lt-label" for="passwd">Password</label>
        [COLOR=Blue]<input class="box" id="passwd"[/COLOR] type="password" name="passwd" [COLOR=Blue]size="15"[/COLOR] alt="password" onclick="login.passwd.value='';"/>  

Hi, considering I reduced my test case to the raw <input> I have to deduce that the problem lies with the size=“15” and the type=“”. Depending on what type, you get a differnet size.

I just think that’s IE6 being IE6 :slight_smile:

Off Topic:

I read your remark about me adding zoom:1;. That was nothing lol. Just me testing stuff out.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<base href="http://www.css-lab.com/test/form-test.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Footer Form</title>

<style type="text/css">


</style>

</head>
<body>
        <input type="text" size="15"/>      
       <br> 
        <input type="password" size="15"/>        

</body>
</html>

Hmm, It seems to have problems with type=“password”, it even gets the height different. That can be seen by removing the <br> tag.

If I change them both to type=“text” just for the sake of testing it gets them both the same.

I’m sure I’m not the first to see this, I wonder how others have dealt with it. I won’t waste too much time with it but it is good to know what the cause is.

Thanks again Ryan :slight_smile:

Probably just a width/height on it lol :slight_smile:

The password uses a different font and therefore the size attribute will be different. Just use the same font.

e.g.


#passwd,#username{font-family:arial}

Now they will be the same :slight_smile:

I always do that for all inputs as they don’t seem to inherit from the parent in IE either.

Yes I’ve seen the bug before and have also recommended a hard clearing element in these cases.

I think your bug relates to these test cases.

IE does seem to have a lot of bugs especially with the last float in a sequence and margin inconsistency is a real pain. A hard clearer usually solves those issues also.

The password uses a different font and therefore the size attribute will be different. Just use the same font.
Great, that worked just fine!

IE does seem to have a lot of bugs especially with the last float in a sequence and margin inconsistency is a real pain. A hard clearer usually solves those issues also.
The reason I was using shrinkwrap floats on the left was because I am going to hove more stuff floated to the right.
I seem to have it all sorted out now. Thanks for the help. :wink: