views:

1333

answers:

4

I have an extremely simple page that isn't displaying properly in IE6. In this browser, the left nav pushes down a table that's in the content area. Can anyone help me get the table to stay at the top of its container where it should be, rather than getting pushed down by content in the left div?

Here's the html code for the page:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
 <head>
  <style type="text/css" media="screen">
   body

   #nav
   {
    float: left;
    width: 180px;
    background-color: #999;
   }

   #content
   {
    margin-left: 210px;
    background-color: #999;
   }

  </style>
 </head>
 <body>

  <div id="nav">
   <div>left content</div>
  </div>
  <div id="content">
   <table style="width: 100%; background-color: #666666">
   <tr><td>table</td>
   </tr>
   </table>
  </div>
 </body>
</html>

Here's a url so you can see what it looks like:

http://www.morganpackard.com/cssTest.html

A: 

You could just make the content float left too:

 #content
 {
     float:left;
     ...
 }

don't forget to adjust the margin-left though


Other solution that doesn't quite work for other browsers though:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
        <head>
                <style type="text/css" media="screen">

                        #nav
                        {
                                float: left;
                                width: 180px;
                                background-color: #999;
                        }

                        #content
                        {
                                float: right;
                        }

                </style>
        </head>
        <body>
            <div id="container">
                <div id="nav">
                        <div>left content</div>
                </div>
                <div id="content">
                        <table style="width: 100%; background-color: #666666">
                        <tr><td>table</td>
                        </tr>
                        </table>
                </div>
            </div>
        </body>
</html>

Notice the container and the float:right;

GoodEnough
The table needs to expand to fill all the available space. Floating elements seems to mess this up.
morgancodes
Any reason why you're using the loose DOCTYPE?
GoodEnough
Only because I'm afraid of using anything stricter.
morgancodes
morgan, you shouldn't be afraid. I use XHTML 1.0 Strict exclusively, and I'm very happy. You will be too if you do the same ;)
Jonathan Sampson
So how about that second solution I added?
GoodEnough
@Crossbrowser, "doesn't quite work for other browsers" won't cut it, I'm afraid.
morgancodes
+3  A: 

Give your table a width of 99% instead.

Jonathan Sampson
AAARRRRRRGGHGGGGGHGHH!!!!! So stupid, but seems to work. Is there any sort of rule I can use to remember this? Any explanation for why this works?
morgancodes
Rhetorical question, right? IE6 cannot be understood ;)
Jonathan Sampson
A: 

If all else fails, go with a table layout *ducks and covers* from the CSS purists:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
        <head>
                <style type="text/css" media="screen">

                        #nav
                        {
                            width: 180px;
                            background-color: #999;
                        }

                        #content
                        {
                            background-color: #999;
                        }

                </style>
        </head>
        <body>
            <table style="width:100%;">
                <tr>
                    <td id="nav">
                        <div>left content</div></td>

                    <td id="content">
                        <table style="width: 100%; background-color: #666666">
                        <tr><td>table</td>
                        </tr>
                        </table></td>
                </tr>
            </table>
        </body>
</html>
GoodEnough
+1  A: 

Another solution is to make the table float left and have a width of 100%....

masterik
True. Just be sure to apply the clear-fix if nothing follows the table.
Jonathan Sampson