开发者

CSS for Nested Lists

开发者 https://www.devze.com 2023-04-09 10:43 出处:网络
I am currently trying to create some nested lists to display the following... A...R...X B...S...Y C...T...Z

I am currently trying to create some nested lists to display the following...

A...R...X

B...S...Y

C...T...Z

(where the letters will eventually be replaced by words) and have made this work perfectly in chrome and firefox, however when I use Internet Explorer I get something resembling the following...

A

B...R

C...S...X

......T...Y

...........Z

I assume it's probably to do with the css, but please can someone help me with this problem, the html and css are shown below, thanks in advance for any help.

HTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel=stylesheet href="lists in IE.css" type="text/css">
</head>
<body>

<div id="container">

    <ul id="links-nav">
        <li>
            <ul>
                <li><a href="#">A</a></li>
                <li><a href="#">B</a></li>
                <li><a href="#">C</a></li>
            </ul>
        </li>
        <li>
            <ul>
                <开发者_开发知识库li><a href="#">L</a></li>
                <li><a href="#">M</a></li>
                <li><a href="#">N</a></li>
            </ul>
        </li>
        <li>
            <ul>
                <li><a href="#">X</a></li>
                <li><a href="#">Y</a></li>
                <li><a href="#">Z</a></li>
            </ul>       
        </li>

    </ul>

    <div class="clear"></div>   
</div>

</body>

</html>

CSS

#container{
    width:940px; 
    margin:0px auto; 
    border: 1px solid #000;
    padding: 20px 10px; 
    height:auto; 
    font-family: Arial, sans-serif; 
    font-size:11px;
}

.clear {
    clear: both;
    height: 0;
    overflow: hidden;
}


a{
    text-decoration:none;
    color:#555;
}

#links-nav li, li ul li{
    list-style:none;
}

#links-nav{
    list-style-type: none;  
    margin:0px;
    padding:0px;
}

#links-nav li ul{
    float:left;
    width:168px;
    padding: 0px 10px;
    list-style-type: none;      
}


add in your css

#links-nav > li {
    width:168px;
    float:left;
}

Demo: http://jsfiddle.net/qUJuy/2/

or

#links-nav > li {
    width:168px;
    display:inline;
}

Demo: http://jsfiddle.net/qUJuy/3/

The above will fix the error in ie7 (in ie8 it was already correct).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号