UL不会留在一条线上

时间:2011-11-11 02:15:16

标签: html css html-lists horizontallist

我尝试了这句话:How to style the UL list to a single line

display: inline;

并没有用!

enter image description here

-----------我的代码-----------

CSS:

*{
margin:0;
padding:0;
}

ul{
list-style:none;
}

#bottom_header{
background:#0F1923;
border-bottom:5px solid #0F67A1;
font-size:.95em;
font-weight:700;
height:31px;
padding:0 0 0 10px;
/*min-width:800px;*/
}

#bottom_header ul li{
font-size:.95em;
margin:0 0 0 6px;
padding:8px;
float:left;
display:inline;
}

#bottom_header ul li.active{
background:transparent url(./tab_left.png) no-repeat top left;
font-size:1.05em;
margin:-4px 0 auto 5px;
padding:0;
position:relative;
}

#bottom_header ul li.active a{
background:transparent url(./tab_right.png) no-repeat top right;
display:block;
margin:0 0 0 6px;
padding:10px 15px 10px 10px;
}

#bottom_header ul li.active,#bottom_header ul li.active a,#bottom_header ul li a:hover{
color:#fff;
text-decoration:none;
}

#bottom_header ul li,#bottom_header ul li a{
color:#aeaeae;
text-decoration:none;
}

HTML:

<div id="bottom_header">
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Forums</a></li>
        <li><a href="#">Something</a></li>
        <li><a href="#">Lorem Ipsum</a></li>
        <li class="left active"><a href="#">Active</a></li>
        <li><a href="#">Another</a></li>
    </ul>
</div>

2 个答案:

答案 0 :(得分:2)

你可以float左边的所有li

实际上,你是这样做的。

只需在width上设置一个<div id="bottom_header">,这样就不会换行。

例如:

#bottom_header{
    background:#0F1923;
    border-bottom:5px solid #0F67A1;
    font-size:.95em;
    font-weight:700;
    height:31px;
    padding:0 0 0 10px;
    width:800px;  /* ADD A WIDTH */
}

示例:http://jsfiddle.net/CtkrZ/

修改

根据您的评论如下:

  

编辑:我设置100%宽度并没有修复它(也创建了一个   在整个页面上始终恼人的水平线)

width移除div并将其添加到ul。同时给ul overflow:hidden;

ul{
    list-style:none;
    overflow:hidden;
    width:500px;   
}

#bottom_header{
    background:#0F1923;
    border-bottom:5px solid #0F67A1;
    font-size:.95em;
    font-weight:700;
    height:31px;
    padding:0 0 0 10px;
}

更新示例:http://jsfiddle.net/CtkrZ/1/

答案 1 :(得分:-1)

ul > li{
   float: left;
}

OR

ul > li{
   display: inline;
}