Solved

IE7 Float / Padding Bug

Posted on 2011-02-23
4
639 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a tile layout 1 36
FTP File permissions 1 45
Element alignment and word wrapping 9 60
Kill default webkit margin!  Please! 6 22
Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…

914 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

20 Experts available now in Live!

Get 1:1 Help Now