Html 选择CSS中的每三个元素
我有一个Html 选择CSS中的每三个元素,html,css,css-selectors,Html,Css,Css Selectors,我有一个无序列表,每个列表项都有一个div 我的HTML是这样的 <ul> <li> <div>.....</div> </li> <li> <div>.....</div> </li> <li> <div>.....</div> </li>
无序列表
,每个列表项都有一个div
我的HTML
是这样的
<ul>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
<li>
<div>.....</div>
</li>
</ul>
注意:我还尝试了:第n个子项
选择器。但是没有运气
希望有人能帮助我。
多谢各位 您试图在
li
中每隔三分之一选择div
元素。由于每个li
中只有一个div
元素,因此未选择任何元素。您应该选择每隔三个li
元素:
li:nth-of-type(3n) > div{
margin-right: 0;
}
li:nth-of-type(3n) > div {
margin-right: 0;
}
您应该使用第n个子项
toli
而不是div
li:nth-child(3n) > div {
margin-right: 0px;
/* other styles comes here */
}
标题让人困惑,这让我把这个问题作为一种重复来结束。
li:nth-child(3n) > div {
margin-right: 0px;
/* other styles comes here */
}