<分区>
<分区>
nav > ul > li {
float: left;
}
#one {
float: left;
}
<nav>
<ul>
<li>
he has a cow
</li>
<li >
he has a dog
</li>
<li>
he has a mouse
</li>
</ul>
</nav>
<div id="main">
<div id="one">
<br/>he has a one</div>
<div id="two">he has a two</div>
<div id="three">he has a three</div>
</div>
现在我的问题是为什么所有列出的三个元素都 float ,尽管我只希望第一个列出的元素 float 。以及为什么 div
元素的行为不像列出的元素。
最佳答案
Now my question is why all listed three items
float
though I just want the first listed item to be floated. And whydiv
elements not behaving like listed items.
有一个difference between class .
and ID #
.
因此,您可以通过以下方式 float 所有列表项:
nav > ul > li {
float: left;
}
如果你只想应用第一个元素,你可以在第一类 .one
中应用它。
请看下面的片段:
.one {
float: left;
}
li {
/*demo*/
width: 100px;
}
<nav>
<ul>
<li class="one">
he has a cow
</li>
<li class="one">
he has a dog
</li>
<li>
he has a mouse
</li>
</ul>
</nav>
<div id="main">
<div id="one">
<br/>he has a one</div>
<div id="two">he has a two</div>
<div id="three">he has a three</div>
</div>
关于html - 列表元素与其他元素的 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35435982/