IE7 width problem

Hi,
I have a three column layout with equalizing columns. It’s been done several times before and there is nothing new about it.

I wanted to see if I could build a content first layout without referring to other layouts for examples on code structure.

It works fine in FF and IE6, but IE7 is having trouble getting the width correct on the Content div (the center column). I had to set the width to 100% to get FF and other browsers to line up the Content div properly.

I also noticed that IE7 doesn’t give a 100% width on my “Expand Column” link in the center column. However it does on the left and right, just wondering if that is related to the width issue mentioned above.

I gave a red background color on one of the wrappers to make the problem easy to spot in IE7. If you drag your browser window left and right you will see a gap on the left of the center column that changes (grows and shrinks) at various stages of viewport width.

Thanks in advance for any ideas on why IE7 doesn’t want to behave.

Here is the complete code to test with, I think the problem lies somewhere within the three selectors I highlighted in red -


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Three Equal Columns ~ Content first in source</title>
<meta name="generator" content="PSPad editor, www.pspad.com" />
<style type="text/css">
/* ---------Reset -------- */
body, address, blockquote, dl, ol, ul, li, form, fieldset, legend, h1, h2, h3, h4, h5, h6, p, pre {
margin:0;
padding:0;
}
/* ------ End Reset ------ */
body {
    background: #BBB;
    padding:20px 0;
}
html {overflow-y:scroll;} /*keep scrollbar present in FF*/

h1, h2, h3, h4, p {
    margin:0;
    padding: 10px 10px 0 10px;
}
#wrapper {
    margin: 0 auto;
    width: 85%;
    min-width:670px;
    max-width:1000px;
    background: #BCC5E1; /*sidebar color*/
    border: 1px solid black; 
    /*overflow:hidden; /* float containment for modern browsers */
}
#header {
    min-height:80px;
    text-align:center;
    border-bottom: 1px solid black;
}
* html #header {height:80px;} /*min height for IE6*/

#navbar {
    height:2em;
    background:#8293C3;
    text-align:center;
    border-bottom: 1px solid black;
}
[COLOR=Red]#contentwrap {
    float:left;
    display:inline;/*IE6 needs this*/
    margin-left:175px;
    margin-right:175px;
    border-left: 1px solid black;
    border-right: 1px solid black;
    background:red; /*#EEF; /*content color*/
}
#innerwrap {
    float:left;
    position:relative;
    /*width:100%;*/
}
#content {
    float:right;
    width:100%;
    background:#EEF; /*content color*/
    padding-bottom:10px;
}[/COLOR]
#left {
    float:left;
    width:175px;
    margin-left:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
}
#right {
    float:right;
    width:175px;
    margin-right:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
}
#footer {
    clear:both;
    height:2em;
    background:#8293C3;
    text-align:center;
    border-top: 1px solid black;
}
p.expand {padding-top:20px;}
p.expand a:hover{
    display:block;
    height:250px;
    background:skyblue;
}
code {font-weight:bold; color:green}
</style>

<!--[if IE ]>
<style type="text/css">
#right {left:1px;}
</style>
<![endif]-->

</head>
<body>

<div id="wrapper">
    <div id="header">
        <h2>Three Equalizing Columns</h2> 
        <h4>Main Content or Left Sidebar can be first in the html source</h4>
    </div>
    <div id="navbar">
        <h4>Navigation</h4>
    </div>
<div id="contentwrap">    
    <div id="innerwrap">
        <div id="content">
            <h2>Main Content</h2>
            <p>With this layout you have the option of locating either the "Main Content" or the "Left Sidebar" 
            first in the html source order.</p>
            <p>The <code>#content</code> div is floated right and the <code>#left</code> div is floated left 
            and they are both contained in the <code>#innerwrap</code> div which is floated as well for the 
            sake of containing it's floated children, either one (content or left sidebar) can come first 
            in the source order without altering the CSS structure.</p> 
            <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
            faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
            eget interdum et Aenean nulla. Nulla Morbi id Curabitur quis et quis metus pellentesque euismod 
            congue. Congue Praesent consequat urna id Sed Curabitur libero ornare platea orci.</p>
            <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
            faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
            eget interdum et Aenean nulla. Nulla Morbi id Curabitur quis et quis metus pellentesque euismod 
            congue. Congue Praesent consequat urna id Sed Curabitur libero ornare platea orci.</p>
            <p class="expand"><a href="#">Expand Column</a></p>    
        </div>
        <div id="left">
            <h3>Left Sidebar</h3>
            <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
            faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
            eget interdum et Aenean nulla.</p>
            <p class="expand"><a href="#">Expand Column</a></p>
        </div>
    </div>
        <div id="right">
            <h3>Right Sidebar</h3>
            <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
            faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
            eget interdum et Aenean nulla.</p>
            <p class="expand"><a href="#">Expand Column</a></p>
        </div>
</div>
    <div id="footer">
        <h4>footer stuff</h4>
    </div>
</div>

</body>
</html>

You should declare the width of the DIV container.

It is the 100% wide div#content that is not always filling the width in IE7. In this case it seems IE7 needs the 100% width to be told by the it’s content. Overflow works that way, but also does justified text.


#content {
    float:right;
    width:100%;
    background:#EEF; /*content color*/
    padding-bottom:10px;
 [COLOR="Red"]   overflow:auto;[/COLOR]
}
<p style="text-align:justify">With this layout you have the option of locating either the "Main Content" or the "Left Sidebar" first in the html source order.</p>

In this case it seems IE7 needs the 100% width to be told by the it’s content. Overflow works that way, but also does justified text.
Thanks erik!

The overflow:auto: on the Content does make IE7 behave now but it started causing problems in FF2. In FF2 the right border on the content div disappears and reappears at various viewport widths.

I know I can target IE7 only with a conditional comment to keep that rule away from FF.

It looks like overflow:hidden; will do the trick for IE7 also without causing problems in FF.


[B]#content[/B] {
    float:right;
    width:100%;
    background:#EEF; /*content color*/
    padding-bottom:10px;
   [COLOR=Blue] overflow:hidden; /*IE7 needs this*/[/COLOR]
}

One other question, I also noticed that IE7 doesn’t give a 100% width on my “Expand Column” link in the center column. I have it set to display:block and it should be 100% wide. It is not an important layout issue since it is only in there for the demo, but it has me confused also. Any ideas why IE7 gets it correct on the side columns but not in the center. :confused:

p[B].expand a:hover[/B]{
    [COLOR=Blue]display:block;[/COLOR]
    height:250px;
    background:skyblue;
}

If I’m not mistaken I see the same issue in FF2. It happens because when you hover on that link in the side column, the a element that now displays block on hover is just pushing down the center column which has 100% width.

But when you hover over the link in the center column its now making that a element display block with the padding you set for p:

h1, h2, h3, h4, p {
margin:0;
padding: 10px 10px 0 10px;
}

remove that padding and hovering over the center column link will now be 100%.

One other question, I also noticed that IE7 doesn’t give a 100% width on my “Expand Column” link in the center column. I have it set to display:block and it should be 100% wide. It is not an important layout issue since it is only in there for the demo, but it has me confused also. Any ideas why IE7 gets it correct on the side columns but not in the center.

Hi Ray - nice layout! Did you figure that out yet? That’s a tough one. It was bugging me too! I worked on it for quite awhile and this was the only combination I was able to come up with that fixed the expandable link thingy. Pretty ugly solution though. But maybe it will give you some ideas… I’m sure now that I answered it, someone else will come in with some one liner fix for it though…

<!--[if IE 7]>
<style type="text/css">
#content p.expand a {
padding:0 100% 0 0;
margin:0 -1px 0 0;
width:1px;
}
#content p.expand span {
float:left;
width:150px;
cursor:pointer;
} 
</style>
<![endif]-->
<p class="expand"><a href="#"><span>Expand Column</span></a></p>

Hi,

The link doesn’t expand full width because its contained in that float that doesn’t have a width. The center section is only pushed wide by the content. If you remove the content then you will see that your heading just lines up at the right of the page with no width.

Don’t float the container and use a clearer instead (or the clearfix method).

This works.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Three Equal Columns ~ Content first in source</title>
<meta name="generator" content="PSPad editor, www.pspad.com" />
<style type="text/css">
/* ---------Reset -------- */
body, address, blockquote, dl, ol, ul, li, form, fieldset, legend, h1, h2, h3, h4, h5, h6, p, pre {
    margin:0;
    padding:0;
}
/* ------ End Reset ------ */
body {
    background: #BBB;
    padding:20px 0;
}
html {
    overflow-y:scroll;
} /*keep scrollbar present in FF*/
h1, h2, h3, h4, p {
    margin:0;
    padding: 10px 10px 0 10px;
}
#wrapper {
    margin: 0 auto;
    width: 85&#37;;
    min-width:670px;
    max-width:1000px;
    background: #BCC5E1; /*sidebar color*/
    border: 1px solid black;/*overflow:hidden; /* float containment for modern browsers */
}
#header {
    min-height:80px;
    text-align:center;
    border-bottom: 1px solid black;
}
* html #header {
    height:80px;
} /*min height for IE6*/
#navbar {
    height:2em;
    background:#8293C3;
    text-align:center;
    border-bottom: 1px solid black;
}
#contentwrap {
    margin-left:175px;
    margin-right:175px;
    border-left: 1px solid black;
    border-right: 1px solid black;
    min-height:0;
    background:#EEF; /*content color*/
}
#innerwrap {
    float:left;
    position:relative;
    width:100%;
}
#content {
    float:right;
    width:100%;
    padding-bottom:10px;
    position:relative;
}
#left {
    float:left;
    width:175px;
    margin-left:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
}
#right {
    float:right;
    width:175px;
    margin-right:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
}
#footer {
    clear:both;
    height:2em;
    background:#8293C3;
    text-align:center;
    border-top: 1px solid black;
}
p.expand {
    padding-top:20px;
}
p.expand a:hover {
    display:block;
    height:250px;
    background:skyblue;
}
code {
    font-weight:bold;
    color:green
}
</style>
<!--[if IE ]>
<style type="text/css">
#right {left:1px;}
</style>
<![endif]-->
</head>
<body>
<div id="wrapper">
    <div id="header">
        <h2>Three Equalizing Columns</h2>
        <h4>Main Content or Left Sidebar can be first in the html source</h4>
    </div>
    <div id="navbar">
        <h4>Navigation</h4>
    </div>
    <div id="contentwrap">
        <div id="innerwrap">
            <div id="content">
                <h2>Main Content</h2>
                <p>With this layout you have the option of locating either the "Main Content" or the "Left Sidebar" 
                    first in the html source order.</p>
                <p>The <code>#content</code> div is floated right and the <code>#left</code> div is floated left 
                    and they are both contained in the <code>#innerwrap</code> div which is floated as well for the 
                    sake of containing it's floated children, either one (content or left sidebar) can come first 
                    in the source order without altering the CSS structure.</p>
                <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
                    faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
                    eget interdum et Aenean nulla. Nulla Morbi id Curabitur quis et quis metus pellentesque euismod 
                    congue. Congue Praesent consequat urna id Sed Curabitur libero ornare platea orci.</p>
                <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
                    faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
                    eget interdum et Aenean nulla. Nulla Morbi id Curabitur quis et quis metus pellentesque euismod 
                    congue. Congue Praesent consequat urna id Sed Curabitur libero ornare platea orci.</p>
                <p class="expand"><a href="#">Expand Column</a></p>
            </div>
            <div id="left">
                <h3>Left Sidebar</h3>
                <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
                    faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
                    eget interdum et Aenean nulla.</p>
                <p class="expand"><a href="#">Expand Column</a></p>
            </div>
        </div>
        <div id="right">
            <h3>Right Sidebar</h3>
            <p>Lorem ipsum dolor sit amet consectetuer ut velit consequat consequat ut. Pede et Suspendisse 
                faucibus Suspendisse dis risus quis fermentum justo egestas. Fusce lacinia non orci Aenean auctor 
                eget interdum et Aenean nulla.</p>
            <p class="expand"><a href="#">Expand Column</a></p>
        </div>
        <div style="clear:both"></div>
    </div>
    <div id="footer">
        <h4>footer stuff</h4>
    </div>
</div>
</body>
</html>


Hope it helps :slight_smile:

If you want ie6 to work you will need to add the display:inline hack to the floats.


#left {
    float:left;
    width:175px;
    margin-left:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
    display:inline
}
#right {
    float:right;
    width:175px;
    margin-right:-176px;
    padding-bottom:10px;
    position:relative; /*IE6 needs this*/
    background:#BCC5E1;
    display:inline
}


Hi Guys,
Sorry I didn’t get a chance to reply back sooner, I got tied up with other work. Thanks everyone for looking through the code and helping me track down the core of the problem with IE.

I finally figured it out (as Paul had pointed out), that having no width on the floated #contentwrap div was confusing IE7. Then as I gave a width of 100% to the Content it had IE7 saying, “100% of what?”
I guess I had assumed that widthless floats would work in IE7 since the current css specs don’t require widths on floats.

The “Expand Column” link not showing the full width like it should was my clue that there were deeper problems in the layout.

                Originally Posted by [B]Paul O'B -[/B]

Don’t float the container and use a clearer instead (or the clearfix method).

@Paul
Thanks for reworking my code into a working layout, I saved a copy of it and will keep it for future reference. I’ll show you how I wound up getting it to work and you can tell me what you think about it, or potential problems you might see with it.

I ended up taking the float away from all IE’s via a conditional comment. I left the float on the #contentwrap (without a width still) for good browsers so that it would contain the floated children, it seems to work fine. Then I gave haslayout to IE via height:1%.
Like this -

[B]#contentwrap[/B] {
   [COLOR=Blue] float:left;[/COLOR] [COLOR=DarkGreen]/*contain inner floats in good browsers, float:none; for IE in CC below*/[/COLOR]
    margin: 0 175px;
    border-left: 1px solid black;
    border-right: 1px solid black;
    background: #EEF; /*content color*/
    [COLOR=Blue]height: 1%;[/COLOR][COLOR=DarkGreen]/*triggers hasLayout in IE*/ [/COLOR]
}
[COLOR=DarkGreen]<!--[if IE ]>
<style type="text/css">[/COLOR]
[B]#contentwrap[/B] [COLOR=Blue]{float:none}[/COLOR]
#right {left:1px;}
[COLOR=DarkGreen]</style>
<![endif]-->[/COLOR]

Then I did wind up placing the width back on the #innerwrap (I had it commented out previously).


[B]#innerwrap [/B]{
    float:left;
    [COLOR=Blue]width:100%;
    [/COLOR]position:relative;
}

Here is the link to what I finally got working in all browsers. I changed the name of the #contentwrap div to #container, so don’t let that cause any confusion.

Thanks again for everyone’s help :slight_smile:

HI Ray,

I still have the same issue with your page (in browsers other than IE) in that it only works when you have 100% content.:slight_smile:

If you have pages that have content like this.


<div id="content">
                <h2>Main Content</h2>
                <ul>
                    <li>test</li>
                    <li>test</li>
                    <li>test</li>
                    <li>test</li>
                    <li>test</li>
                    <li>test</li>
                    <li>test</li>
                </ul>
                <h5 class="expand"><a href="#">Expand Column</a></h5>
            </div>

Your page will break badly.

Although the widthless float seems to be working it only works when content pushes it 100% wide and you can’t assume that every page will do that as the code above shows.

Considering the hacks you need to add for this method anyway then the solution I offered is far neater even if it does need a clearer (which can be via the clearfix method if you don’t want an extra div).

Otherwise its working well :slight_smile:

Although the widthless float seems to be working it only works when content pushes it 100% wide and you can’t assume that every page will do that as the code above shows.

Ahh, I see what you are saying now! Yes I agree that your method is neater and I will go with it.

Thanks for helping :slight_smile: