Solved

IE7 Float / Padding Bug

Posted on 2011-02-23
4
651 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

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 43

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 43

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
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 style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

728 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