[英]Floating li items with css for more than one Ul items
Let's take this html code: 让我们看一下这个html代码:
<div>
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
<ul>
<li>ddd</li>
<li>fff</li>
<li>eee</li>
</ul>
</div>
The result is ok, of course. 结果当然可以。 But, now I want to make all li
items inside the ul
s horizontally with the help of this CSS
: 但是,现在我想借助此CSS
将ul
内部的所有li
项水平放置:
li{
float:left;
list-style:none;
}
But, the result is: fiddle 但是,结果是: 提琴
I can add </br>
between div
's. 我可以在div
之间添加</br>
。 But, it is not the correct way. 但是,这不是正确的方法。 Thanks. 谢谢。
Add a width property to li to distribute them horizontally and align the uls horizontally: 在li中添加width属性,以使其水平分布并沿ul水平对齐:
ul{
text-align: center;
}
li{
float: left;
list-style: none;
width: 16.5%;
}
This will work for a fixed number of list items. 这将适用于固定数量的列表项。
You can inline the <ul>
elements inside the div. 您可以内联div中的<ul>
元素。
ul {
display:inline;
text-align:center;
margin:10px 0; // This is to avoid scrollbars in the demo, might not be necessary for you
padding:0;
}
li {
display:inline;
list-style:none;
}
Here is a demo: http://jsfiddle.net/4pv6rby9/14/ . 这是一个演示: http : //jsfiddle.net/4pv6rby9/14/ 。
use margin. 使用保证金。
li{
float:left;
list-style:none;
margin: 10px;
}
Use clear both- HTML: 两者都使用-HTML:
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
<div style="clear:both;"></div>
<ul>
<li>ddd</li>
<li>fff</li>
<li>eee</li>
</ul>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.