Solved

IE7 Float / Padding Bug

Posted on 2011-02-23
4
634 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:Chris Stanyon
  • 2
4 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34965318
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.
0
 
LVL 42

Author Comment

by:Chris Stanyon
ID: 34965434
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 !

0
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
ID: 35323979
It's a difference in how IE versions before 8 handle shrink-wrapping of floated elements that don't have set widths. Can you set a width on "#doublecolumn"? Another alternative would be to give "overflow:auto" or "overflow:hidden" to "#doublecolumn" instead of "float:left".
0
 
LVL 42

Author Comment

by:Chris Stanyon
ID: 35324446
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
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now