views:

134

answers:

2

I have the following page (which is reduced and modified from ASP.NET MVC default project):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>test</title>
<style type="text/css">
body
{
    background-color: #fff;
    font-size: 62.5%;
    margin: 0;
    padding: 0;
}
.page
{
    width: 90%;
    margin-left: auto;
    margin-right: auto;
}
#header
{
    position: relative;
    padding: 0;
}

#header h1
{
    font-weight: bold;
    padding: 5px 0;
    margin: 0;
    color: #000;
    border: none;
    line-height: 2em;
}

/* TAB MENU   
----------------------------------------------------------*/
#menu
{
    clear: both;
    width: 100%;
    float: left;
    margin: 0;
    padding: 0;
}

#menu *
{
    margin: 0;
    padding: 0;
}

#menu ul
{
    list-style: none;
    width: 12em;
    float: left;
}

#menu li
{
    position: relative;
    background-color: #fff;
    border: solid 1px #fff;
}

div#title
{
    display: block;
    float: left;
    text-align: left;
}

</style>
</head>
<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>
                    test</h1>
            </div>
            <br />
            <div id="menu">
                <ul>
                <li><a href="#">Menu1</a></li>
                </ul>
                <ul>
                <li><a href="#">Menu2</a></li>
                </ul>
                <ul>
                <li><a href="#">Menu3</a></li>
                </ul>
                <ul>
                </ul>
            </div>
        </div>
    </div>
</body>
</html>

When I view it in FireFox, the list in #menu div shows up aligned with the header above flush against the left edge of .page div. However, in IE6, the list inside #menu is indented. I have a suspicion that it's margin-left: auto that's being inherited by the list element.

How do I fix it so that the list is flush up against the left edge of the #menu div?

A: 

Change your li class to this:

#menu li
    {
        background-color: #fff;
        border: solid 1px #fff;
    }

So bascally just get rid of the position decleration.

ssergei
I cannot - because the <li> will contain <ul> as sub-menu that will be absolutely positioned, which mean <li> needs to be relatively/absolutely positioned.
Jiho Han
+1  A: 

Change your class to not include position: relative, but add this to the top:

body * {
 position: relative; 
}
orokusaki
Hmm... this works but seems pretty onerous. It actually broke other parts of my page (not shown) Can you explain why this works? Perhaps then I can apply it further.
Jiho Han
@Jiho This is the correct way to do it, and not a hack. What this does is position everything in your document relative to it's parent element (ie a `<div>` inside of another `<div>`, the one inside exists relatively to it's parent (which is only natural)). Then, when you need something to be absolute positioned, you can rest assured that it will be absolutely positioned based on its parent, and when you float something, you know it's floating in its parent. The `body *` says `everything inside the body tag`. Checkout O'reily's book "The Definitive Guide to CSS".
orokusaki