/    Sign up×
Community /Pin to ProfileBookmark

IE6 DIV FLOAT:LEFT – is it really so hard?

Hiya. Ok, so I have 2 containers on the page:

#ltcon01 {
float:left;
width: 345px;
}

#rtcon01 {
width: 345px;
margin-left: 355px;
}

Their CSS attributes are further defined in these classes:

.convar {
position: relative;
}

.padding {
position: relative;
border: 1px solid #CCC;
padding: 8px 10px 10px;
}

implemented as such:

<div class=”convar” id=”ltcon01″>

<div class=”padding” id=”l01″>content here</div>
<div class=”padding” id=”l02″>content here</div>
</div> <!– end ltcon01 –>

<div class=”convar” id=”rtcon01″>
<div class=”padding” id=”r01″>content</div>
</div> <!– end right cont 01 –>

the containers display as they should – that is, next to each other – their tops with the same vertical position in FF, Opera and IE7. Alas in IE6, the right container begins at the correct horizontal coordinates, due to its padding. But, its vertical position is set right at the bottom of the first container. If I make rtcon float:right, it doesn’t seem to make any difference. How on earth am I going to get my layout to work in IE6?

Any help much appreciated!

Z

to post a comment
CSS

9 Comments(s)

Copy linkTweet thisAlerts:
@ZepharimauthorMar 08.2007 — Um, ok it won't let me edit that post since my 10 mins are up. Ahem. Well, I figured the problem was because they are contained in another container that is set to 700px. So now my only problem is the 3px padding that ie adds. How ridiculous is that? What's the best workaround, to you guys knowledge, to make this display consistently across browsers. It is rather important that I get my right two columns exactly 10 pixels apart.

Thanks!

Z
Copy linkTweet thisAlerts:
@LyricsLadyMar 08.2007 — [B][COLOR="Black"][/COLOR][/B]

Hi,

I just joined, I don't know what has happened to Internet Explorer 6 and or 7, I have a beautiful website with poems I write posted there, and for years I had no problems, I went back into the hospital, when I came home, I looked at my site and cried my eyes out, on each page, images had turned into empty boxes with red x(s) in them. I DL Fire Fox and saw everything beautifully, same with Sea Monkey, but I don't know how to DL anything with those two, and most of my visitors are I.E. browser users who also have the same problems with their website, cause they also have I.E.. Please can you shed any light on this problem? I have windows XP home edition, and I am not computer savvy at all. I would be so grateful if anyone knows the solution, for I have exhausted myself trying.

Thanks

and God Bless!
Copy linkTweet thisAlerts:
@WebJoelMar 08.2007 — Post your entire code or URL to site. It is difficult to analyze your page with just the code you provided. ?
Copy linkTweet thisAlerts:
@WebJoelMar 08.2007 — Maybe something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html><head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta http-equiv="Content-Style-Type" content="text/css" />

<meta http-equiv="Content-Script-Type" content="text/javascript" />

<title></title>

<style type="text/css">

* {border:0; padding:0; margin:0;}/* Set everything to "zero" */

body {min-height:100%; height:101%;

font:x-small Arial, Verdana, sans-serif;

voice-family: ""}"";voice-family:inherit;

font-size:small;/*for IE 5.5 */

} html>body {font-size:small;}

/*font-size: small; voice-family: ""}"";

voice-family: inherit; font-size: medium;*
/} /* Assist IE rendering height, keyword-font sizes, etc. */

p {font-size: 90%; line-height:1.2em; margin-top:6px;}

h1, h2, h3, h4, h5, h6 {font-family: 'times new roman', arial, verdana, serif; background-color:none;

font-style:normal; font-variant:normal; font-weight:normal; margin:11px 0 0 10px;}

h1{font-size: 1.93em; margin-top:12px;}

h2{font-size: 1.72em; margin-top:12px;}

h3{font-size: 1.52em; margin-top:12px;}

h4{font-size: 1.42em; margin-top:12px;}

h5{font-size: 1.32em; margin-top:12px;}

h6{font-size: 1.21em; margin-top:12px;}

#ltcon01 {float:left;width: 345px;}

#rtcon01 {width:345px; float:left;}

.convar {position: relative;}

.convar DIV {position: relative;border: 1px solid #CCC; padding: 8px 10px 10px; margin:0 15px 15px 0;}

</style>

<link rel="shortcut icon" href="favicon.ico"><!-- path to your favicon -->

</head>

<body>

<div style="width:694px; height:auto; margin:15px auto; padding:15px 15px 0 15px;">

<div class="convar" id="ltcon01">

<div id="l01"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Suspendisse egestas ultricies pede. Phasellus suscipit blandit risus.

Praesent nonummy. In erat. Duis nibh pede, accumsan eu, pulvinar et,

volutpat vel, elit. Curabitur nec dui sed nunc congue tempus. Nulla ac

dui ac libero fringilla nonummy. Maecenas ullamcorper sodales risus.

Vivamus pretium dolor. Proin eu turpis. Phasellus ut mauris non nulla

mattis luctus. Nunc porttitor dapibus sapien. In malesuada fermentum

metus. Nulla egestas, tellus a vestibulum pharetra, nunc purus auctor

lacus, ut semper purus ipsum eu velit. Praesent dui. Nulla accumsan

turpis at erat.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.

Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium

quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar

purus, vel hendrerit ipsum tellus at ante.</p>

</div>


<div id="l02">

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Suspendisse egestas ultricies pede. Phasellus suscipit blandit risus.

Praesent nonummy. In erat. Duis nibh pede, accumsan eu, pulvinar et,

volutpat vel, elit. Curabitur nec dui sed nunc congue tempus. Nulla ac

dui ac libero fringilla nonummy. Maecenas ullamcorper sodales risus.

Vivamus pretium dolor. Proin eu turpis. Phasellus ut mauris non nulla

mattis luctus. Nunc porttitor dapibus sapien. In malesuada fermentum

metus. Nulla egestas, tellus a vestibulum pharetra, nunc purus auctor

lacus, ut semper purus ipsum eu velit. Praesent dui. Nulla accumsan

turpis at erat.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.

Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium

quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar

purus, vel hendrerit ipsum tellus at ante.</p>

</div>


</div> <!-- end ltcon01 -->

<div class="convar" id="rtcon01">

<div>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Suspendisse egestas ultricies pede. Phasellus suscipit blandit risus.

Praesent nonummy. In erat. Duis nibh pede, accumsan eu, pulvinar et,

volutpat vel, elit. Curabitur nec dui sed nunc congue tempus. Nulla ac

dui ac libero fringilla nonummy. Maecenas ullamcorper sodales risus.

Vivamus pretium dolor. Proin eu turpis. Phasellus ut mauris non nulla

mattis luctus. Nunc porttitor dapibus sapien. In malesuada fermentum

metus. Nulla egestas, tellus a vestibulum pharetra, nunc purus auctor

lacus, ut semper purus ipsum eu velit. Praesent dui. Nulla accumsan

turpis at erat.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.

Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium

quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar

purus, vel hendrerit ipsum tellus at ante.</p>

</div>

<div>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Suspendisse egestas ultricies pede. Phasellus suscipit blandit risus.

Praesent nonummy. In erat. Duis nibh pede, accumsan eu, pulvinar et,

volutpat vel, elit. Curabitur nec dui sed nunc congue tempus. Nulla ac

dui ac libero fringilla nonummy. Maecenas ullamcorper sodales risus.

Vivamus pretium dolor. Proin eu turpis. Phasellus ut mauris non nulla

mattis luctus. Nunc porttitor dapibus sapien. In malesuada fermentum

metus. Nulla egestas, tellus a vestibulum pharetra, nunc purus auctor

lacus, ut semper purus ipsum eu velit. Praesent dui. Nulla accumsan

turpis at erat.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Morbi lacus felis, euismod at, pulvinar sit amet, dapibus eu, eros.

Etiam tellus. Nam vestibulum porttitor urna. Phasellus aliquet pretium

quam. Proin pharetra, wisi nec tristique accumsan, magna sapien pulvinar

purus, vel hendrerit ipsum tellus at ante.</p>

</div>



</div> <!-- end right cont 01 -->

</div>

</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@CentauriMar 08.2007 — Try NOT specifying a width for #rtcon01, and let it fill the space naturally.

Cheers

Graeme
Copy linkTweet thisAlerts:
@ZepharimauthorMar 09.2007 — Hey guys, I'm sure the problem is with ie. The code I posted will actually display the erroneus problem - the div on the right will be 13px to the right instead of the intended 10px. IE6 and below seems to add 3px of padding to anything set to the side of a floated div, as shown here:

[URL="http://www.positioniseverything.net/explorer/threepxtest.html"]



As far as not specifying the width for the div on the right, that didn't seem to help. I guess it's just that IE has this render bug and the only way around it is via a trick.



I don't have much energy to try and figure out some kind of hack for it, as I can't seem to get an easy to understand answer from all these other sites that describe ways of fixing it. The link above seems to help in regards to fixing text that is put out of alignment, but not how to fix an entire div. I see it is a rather well documented problem with ie6. So for now, as it's just a few elements in the site I think I'll just use a table with 3 columns, 345px 10 px and 345 px. (as was used before, except before the entire site was made with tables) It doesn't bulk up the code, and it works just fine in all my browsers. I can also put back the containing divs later when there is a workable solution that is not too complicated. I know that tables aren't supposed to be used for layout, but why should I make myself go crazy with finding some way around the ie bug, when I can just use something I'm familiar with, that works?



Of course if someone can show me a really simple way of getting around that 3px bug, I'm all ears. For now though, tables will have to do, as I'm already running behind time in getting this site up.
Copy linkTweet thisAlerts:
@CentauriMar 09.2007 — How about [CODE]* html #rtcon01 {
margin-left: 352px;
}
[/CODE]


Cheers

Graeme
Copy linkTweet thisAlerts:
@ZepharimauthorMar 09.2007 — How about [CODE]* html #rtcon01 {
margin-left: 352px;
}
[/CODE]


Cheers

Graeme[/QUOTE]


Hey thanks, that works. I feel a bit silly now. I thought I had tried that fix, and it appeared to have not worked before, but now it does work, so I must have made a mistake before. Now my layout shows correctly in FF, Opera and IE6. So that css expression is only read by IE6 and below?
Copy linkTweet thisAlerts:
@WebJoelMar 09.2007 — Of course if someone can show me a really simple way of getting around that 3px bug,...[/QUOTE]

Whether you use TABLE or DIV, probably it is best to always start your <STYLE> statement with this:

<style>

* {margin:0; padding:0;}

</style>

Make this the [I]first[/I] statement in your CSS so that all following entries abide this first rule.

This removes ALL default margins & padding from ALL elements. IE tends to throw in a pixel or two here on everything, -often with disappointing results.

Downside to this is that you would now also need to re-state the default for [I]all subsequant tags[/I] that, in the absence of 'default margin & padding', now needs them. Notably, the "<p>" suffers the most, so it needs some margin at least.

Let's say your "<h1>" is not 'spaced' nicely anymore due to this zero-inig out of the margins & padding... let's now give ALL the "h" tags in <STYLE> something to start with:

<style>

* {margin:0; padding:0;}

[U]h1, h2, h3, h4, h5, h6 {[B]margin:12px 0 6px 14px;[/B]}[/U]

</style>

So now, ALL the "<h>" tags will have a 'top-margin' of 12px, 'zero' for margin-right, 6-px margin-bottom and a nice left-indent ('margin-left') of 14px.

(margin:12px 0 6px 14px; = margin:[U]top[/U] [U]right[/U] [U]bottom[/U] [U]left[/U]).

I know that this must look like a lot of extra typing, -but once defined (and even possibly saved as a re-useable template), you are yards ahead of the game and it is a major time-saver on future page-builds. Not to even mention that your pages will be more cross-browser similar because the defaults are re-set. ?
×

Success!

Help @Zepharim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...