【发布时间】:2013-11-07 23:18:38
【问题描述】:
我想相对于它的父元素而不是相对于文档来设置第 n 个元素的样式。 明白了:
css:
ul li:nth-child(2n){ background: #fff; }
html:
<ul>
<li></li> // background is white
<li></li>
<li></li> // background is white
</ul>
<ul>
<li></li>
<li></li> // background is white
<li></li>
</ul>
在这种情况下,每个第二个元素获取一个白色背景,从文档开始计数,元素获取父元素“ul”无关紧要。
现在我希望在每个“ul”元素处重新设置计数。结果应如下所示:
<ul>
<li></li> // background is white
<li></li>
<li></li> // background is white
</ul>
<ul>
<li></li> // background is white
<li></li>
<li></li> // background is white
</ul>
谁能帮帮我?
【问题讨论】:
-
您在发布代码之前检查过代码吗?
标签: css css-selectors