Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IE7 Float / Padding Bug

Posted on 2011-02-23
4
Medium Priority
?
658 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 84

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 44

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 43

Accepted Solution

by:
David S. earned 2000 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 44

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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 to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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 …
Suggested Courses

604 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