gothwalk: (hope springs eternally from my fist)
gothwalk ([personal profile] gothwalk) wrote2005-07-11 03:15 pm
Entry tags:

CSS Layout Query

I'm having an interesting CSS issue here in Internet Explorer 6 - not showing in Firefox or Opera.

Extracts from my code:

HTML:

<div id="container">
<div id="info"></div>
<div id="content"></div>
</div>

CSS:

#container {
width: 778px;
position: absolute;
left: 50%;
margin-left: -375px;
border-left: 1px solid #382A7E;
border-right: 1px solid #382A7E;
}
#info {
width: 211px;
float: right;
}
#content {
width: 566px;
border-right: 1px solid #382A7E;
}


Now, what's happening in IE is that the info div is too wide, and is pushing the content div down the page. Reducing the width of the info div by 3 pixels to 208 makes it narrow enough, but this isn't ideal - I need every pixel of that 211.

My first conclusion on some research was that this is a manifestation of IE's box-model problems, wherein it puts borders inside the total width, not outside, so that IE would only see 776 pixels to work with #container. However, widening #container by 2px to give it the "full" 778 didn't work - and leaves some ugly gaps in Firefox and Opera.

The 3-pixel difference does lead to to think that it might be something to do with the borders, though...

Anyone able to explain to me what's happening here?

EDIT: Solved by [livejournal.com profile] loupblanc, by adding "float: left;" to #content. Genius!

[identity profile] yrthilian.livejournal.com 2005-07-11 07:39 am (UTC)(link)
did you try setting your border to 0pix or do you need them?

although looking at it you do but it is only a suggestion.
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 07:46 am (UTC)(link)
I tried removing the border declaration altogther, and that's still giving the same layout issue - which is downright bizarre, as far as I can see.

[identity profile] yrthilian.livejournal.com 2005-07-11 07:40 am (UTC)(link)
were is this page i might be able to have a look at it if you dontmind that is
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 07:45 am (UTC)(link)
It's only on a development server at the moment, so you won't be able to see it.

[identity profile] loupblanc.livejournal.com 2005-07-11 07:42 am (UTC)(link)
As far as I understand this, IE doen't interpret the box model the same way gecko-based browsers do. So the width attribute in IE refers to width of content + width of borders + width of padding. The margins are not included _I think_

Usually, I try to avoid using padding altogether to avoid having to use hacks for IE.

One thing you *might* want to try is use "display: inline" in #container

IE always give me headaches when I code, so good luck.
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 07:48 am (UTC)(link)
One thing you *might* want to try is use "display: inline" in #container

Good notion, but no luck. :(

IE always give me headaches when I code, so good luck.

It's a foul beast. However, with 97%+ of our clients using it, I've no option but to cater for its foulness.

[identity profile] mollydot.livejournal.com 2005-07-11 07:47 am (UTC)(link)
Probably not much use, but I found increasing #container by 4 worked (though obviously leaving extra space in firefox). Decreasing #content by same amount worked too.

[identity profile] mollydot.livejournal.com 2005-07-11 07:50 am (UTC)(link)
Or 2 works if you remove the margins.
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 07:51 am (UTC)(link)
3 seems to be enough for it, which leads me to believe that it's the borders doing the damage. But then I tried it with no borders, and it's still out of place. Hates it, we does, hates it.

[identity profile] mollydot.livejournal.com 2005-07-11 07:53 am (UTC)(link)
Tricksy, fat browser.

[identity profile] loupblanc.livejournal.com 2005-07-11 07:59 am (UTC)(link)
add float: left; to #content
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 08:04 am (UTC)(link)
Perfect! Absolutely fantastic, thanks a million!

[identity profile] loupblanc.livejournal.com 2005-07-11 08:05 am (UTC)(link)
No worries :)

I like your method of centering btw, much less clunky than mine :)
ext_34769: (Default)

[identity profile] gothwalk.livejournal.com 2005-07-11 08:06 am (UTC)(link)
The product of much frustration, that. :)

[identity profile] loupblanc.livejournal.com 2005-07-11 08:13 am (UTC)(link)
Tell me about it, if my doctype isn't right, my combo of margin: 0px auto and text-align: center won't work.

I might try your solution, see if it works for me when I next have to make a centered website :)

[identity profile] mollydot.livejournal.com 2005-07-11 08:06 am (UTC)(link)
Bah. Glad I refreshed the comments before doing a repeat post!