Link to home
Start Free TrialLog in
Avatar of Chris Stanyon
Chris StanyonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

IE7 Float / Padding Bug

I'm fairly sure this is an IE7 bug to do with padding and floats on my DIVs but I can't figure out which bug it is (or how to fix it). It only seems to be a problem in IE7.

The code below should render three columns wrapped in a DIV, all aligned horizontally. In IE7 the third column drops below the second. I can fix this by removing the 5px left and right padding of the #wrapper div, by removing the double column div altogether, or by widening my wrapper by 5px - none of these are acceptable solutions !

I've looked into the double margin / padding bug but not sure that it applies here. It doesn't seem to be doubling the padding (not visually anyway). Adding display:inline doesn't fix the issue either, as suggested by others.

I'd rather not 'hack' the CSS or apply conditional rules if I can help it - but hey - if needs must :)

Just trying to figure out why it's happening, and how to elegantly fix it.


<style type="text/css">
body { padding: 20px; }
#wrapper { width: 750px; padding: 5px; border: 1px solid #000000; margin: 0px auto; overflow:hidden; }
#col1 { background-color: #ff0000; width:250px; height:50px; }
#col2 { background-color: #00ff00; width:250px; height:50px; }
#col3 { background-color: #0000ff; width:250px; height:50px; }
.leftcol { float: left; }
</style>

<body>
<div id="wrapper">
	<div id="col1" class="leftcol">
	</div>

	<div class="leftcol" id="doublecolumn">
		<div id="col2" class="leftcol">
		</div>
	
		<div id="col3" class="leftcol">
		</div>
	</div>
</div>
</body>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

There's something about the double column div.  In IE6 you have to remove it and change the 'colx' divs to 249px to get them to float side by side.  And you have to have a DOCTYPE or it doesn't work.
Avatar of Chris Stanyon

ASKER

Dave,

Thanks. The code I posted above is just a snippet - I'm using a strict Doctype - totally valid and compliant.

I'm not concerned about IE6. It's IE7 that I need to get it working in - although I'm guessing it's the same problem / solution in both.

Removing the doublecolumn div isn't an option - it's needed for other bits. Changing the widths also isn't an option - it works perfectly in all other browsers as it is. I'd rather not break all other browsers to satisfy IE7 !

ASKER CERTIFIED SOLUTION
Avatar of David S.
David S.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Kravimir,

I did sort this one out by setting a width on the double column, but left the question open to see if there was an explanation as to why it was a problem in IE7.

Can't quite remember the application of the code I posted above so not sure whether your other suggestions would have been suitable.

I'll award you the points and close this one off.

Thanks