views:

197

answers:

3

In the following example, the right side container appears to the right of the left side one in standards compliant browsers, but in IE6 the blue right side container appears below the left side one. IE6 effectively bumps it down because the parent container is narrower than the total width of the left and right side containers.

I have the following HTML:

<html>
    <head>
       <style>
  #parentcntnr{
   width: 900px;
   border: 3px solid black;
  }

  #leftside{
   width: 200px;
   float: left;
   background-color: red;
   position: relative;

  }

  #rightside{
   width: 800px;
   background-color: blue;
   margin-left: 210px;
  }

 </style>
</head>
<body>
 <div id="parentcntnr">
  <div id="leftside"> content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br> content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br></div>
  <div id="rightside">content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br></div>
 </div>
</body>

How do I make this render like it does in Firefox 3.5? I'd like the right and left side containers to remain side by side and a horizontal scroll bar to appear when the parent container is smaller than the total width of the child containers.

For the record: this is an example that exhibits a problem that I'm having on a website. The above behavior occurs when the browser window is sized so that it is narrower than the sum of the two child widths. This poses a problem for clients with low screen resolutions.

A: 

If you put your right floating element before the left floating element in the source tree:
<div id="parent">
    <div id="rightSide" />
    <div id="leftSide" />
</div>
that should take care of your floating issue. I'm not certain if you can prevent them from breaking when the parent container is too narrow though, IE6 has some funky overflow logic that's for sure.

zack
This seems only to make the red left side container render below the blue right side one, with a square of white space above the left side container.
Jack
+2  A: 
<html>
<head>
   <style>
            #parentcntnr{
                    width: 900px;
                    border: 3px solid black;
            }

            #leftside{
                    width: 200px;
                    float: left;
                    background-color: red;
                    position: relative;

            }

            #rightside{
                    width: 800px;
                    background-color: blue;
     position: absolute;
     float: right;
            }

    </style>
</head>
<body>
    <div id="parentcntnr">
            <div id="leftside"> content </br>content </br>content </br>content  </br>content </br>content </br>content </br>content </br> content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br></div>
            <div id="rightside">content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br>content </br></div>
    </div>

This fixes it. YOUR WELCOME JACK!

Karl
Doesn't work in the better browsers. Under each Firefox and the newest IE8.
BalusC
Yup, but you can add _position: absolute; _float: right;instead, this will address only IE6.
Karl
Sorry, but positioning it absolute makes no sense.
BalusC
Neither does IE6, but it works.
Karl
A: 

Before continuing, you need to ensure that you're using the right doctype. Use <!doctype html>. You also need to replace all those wrong </br> elements by <br>.

First problem is that the #rightside is too wide. It's 800px, while there's only 700px left after filling a 900px wide container with a 200px wide content, the #leftSide. So:

#rightside{
    width: 700px;
}

should fix it.

Second problem is that you aren't floating the #rightSide anywhere. It won't float left or right from the #leftSide. We want to have it on the right side, so

#rightside{
    float: right;
}

should fix it. This also makes the margin-left completely superfluous.

Now it should look fine in the older IE browsers (just because they are buggy on floats). But in the better browsers the container div wouldn't wrap the both floated elements. That's true, you still need to clear the both floats afterwards. This is to be done by adding basically

<br style="clear: both;">

as the last element of the container div.

Now, the final result which works across all browser should look like:

<!doctype html>
<html>
    <head>
       <style>
            #parentcntnr {
                width: 900px;
                border: 3px solid black;
            }
            #leftside {
                width: 200px;
                float: left;
                background-color: red;
            }
            #rightside {
                width: 700px;
                float: right;
                background-color: blue;
            }
            . clear {
                clear: both;
            }
        </style>
    </head>
    <body>
        <div id="parentcntnr">
            <div id="leftside"> content <br>content <br>content <br>content  <br>content <br>content <br>content <br>content <br> content <br>content <br>content <br>content <br>content <br>content <br>content <br>content <br>content <br></div>
            <div id="rightside">content <br>content <br>content <br>content <br>content <br>content <br>content <br>content <br>content <br></div>
            <br class="clear">
        </div>
    </body>
</html>

Hope this helps.

BalusC
I think you missed the point of the question. The right side has to be wider than the fixed width of the parent container. So you can't change the width to 700px. The overly wide #rightside should force a horizontal scroll bar and NOT drop down before #leftside.
Jack