tags:

views:

44

answers:

4

Hello,

not sure why this isn't working-- i have 3 divs where the two on the side are empty, and all my content in the middle. IE6 is apparently ignoring the empty divs, as the content is pushed to the left. Any ideas what the problem could be?

.sidebar {
float: left;
width: 25%;
height:auto;
visibility:hidden;
font-size:1px;
line-height:0;
}

.main {
width: 50%;
height:auto;
float:left;
}
<div class="sidebar"><p> </p></div>
<div class="main">
...
</div>
<div class="sidebar"><p> </p></div>

I've tried putting empty comments instead of empty paragraphs in the divs, tried putting   in the divs, anything the internet said to do, to no luck. let me know if you want to see the content in the main.

Thanks!

+1  A: 

I believe this is a situation where if the divs on the side are going to remain empty, you'll have to specify height or at least a min-height to make it show up. Alternately, again if they're going to remain empty, you could simply remove them and use margin: 0 auto 0 auto to center your middle column. IE6 in particular has some issues with non-breaking spaces that can cause all sorts of weird things to happen, but only in certain specific versions of IE6. Ahh, the joys of browsers.

Note that height:auto won't stretch anything if it doesn't know what to stretch to, just like height: 100% won't work without a div of known size to 100% to. From your question it doesn't seem like you're trying to stretch it to fill the screen, but it's something to be aware of.

A css framework such as 960.gs, YUI grids, or Blueprint would make this a cakewalk...I'm just sayin'

bpeterson76
This is infuriating! Your tip makes perfect sense but neither setting a height (i put 20px) to the sidebars nor removing the sidebars and putting margin:0 auto (that screws the layout up on firefox as well..) in the main works... could it be something with my content?? im making a series of ul's taken from a database (via cf) with 4 lis per ul per line.Thanks so much for your quick response. This site is so great..
Eric
@Eric: Unfortunately without being able to see the code in action with your content, we're only guessing now. It could be that your <li>'s are too wide and are forcing the .main content to be wider than 50% width, which would subsequently push it down and squish it against the left edge.
Pat
Actually, Pat is likely onto something. In my experiences when you make your columns add up to 100%, bad things happen due to IE's stupidity on box model rendering. Just for kicks, assign a height, cut your columns down to like 90% combined, and see if that makes a difference.
bpeterson76
YES! cutting the sidebars down to 20% worked very well. thanks so much! who do i give the best answer to in this case? sorry, my noob is showing...
Eric
A: 

I'm not seeing the bug on my end in IE6. I pasted your example into a .html doc and it worked correctly (IE6 respected the hidden .sidebar's).

Out of curiosity, what are you trying to do? If you just want a centered .main container, you can do it with the following markup:

<div style="width: 50%; margin: 0 auto;">
    Centered content, 50% width of its parent container.
</div>
Pat
see comment above. thanks so much for responding so quickly.
Eric
A: 

I think what's happening is that your divs are not actually floating.

if you are doing 25%-50%-25%, IE will not have enough room for them to float.

Try testing with something smaller, like 20%-45%-20%

It sounds ridiculous, but it's true. IE6 will not allow you to add width percentage up to 100%.

Also, we need to see more code to further troubleshoot this for you... http://www.jsfiddle.net/

vinhboy
A: 

The HTML element for a non-breaking space is

&nbsp;

Which you can use to make the divs show up. This can cause issues if you want a very small div, since the space has a line-height and all that, but it can be useful in some cases.

smdrager