I have two floating elements: one is floating to the left, other one is inside it floating to the right. Everything is working in all browsers, except for IE7. For some reason IE7 expands width of parent div to fill all available area.
I did not find a solution to the bug (maybe others will), but I did find a suitable work around. This plays exactly the same as the other code, but also works in IE7/6.
<!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">
<style type="text/css">
<!--
#test1 {
border:solid 1px red;
float:left;
padding:0 57px 2px 0;
position:relative;
}
#test2 {
width:50px;
border:solid 1px blue;
position:absolute;
right:0;top:0;
}
-->
</style>
</head>
<body>
<div id="test1">
<div id="test2">float</div>
Text on left
</div>
</body>
</html>
What is happening here is when you have a widthless float and then inside of that an element with hasLayout IE will stretch the float to 100% imitating IE5 mac behavior.
The fix is to either remove the hasLayout cuase (the height:5px) and use padding to give the height
Ryan, even though that works and you are correct about haslayout causing the problem I wouldn’t call it a fix. I would call it a workaround, the true fix came in IE8 when IE’s broken float model and haslayout issues were finally confronted. As we all know a block level element should fill it’s parent’s width according to the specs (with or without a height).
The IE float model bugs are numerous and then with haslayout thrown into the mix it just complicates things even more -
The bad thing about all this is that IE7 will linger around for many years just like IE6 and all these workarounds will still need to be used even though IE8 fixed many of the problems.
Yes the nromal fix is to float the inner element but as that was the case I was like…er…lol.This normally happens on navigation menus. Yes more of a workaround.