【发布时间】:2015-01-04 16:30:12
【问题描述】:
我想让一些框根据它们是组中的奇数还是偶数框而具有不同的属性,但仅适用于多个类的选择器:但它包括原始 box 类的对象,尽管它不是在 nth-child 的 CSS 选择器中:
<div class="box">1</div>
<div class="box special">1</div>
<div class="box special">1</div>
.box
{
width: 100px;
height: 50px;
background-color: #e3e3e3;
}
.box.special:nth-child(odd)
{
background-color: red;
}
.box.special:nth-child(even)
{
background-color: blue;
}
第三个框应该是蓝色的,但它是红色的!第二个应该是红色的,但它是蓝色的!
【问题讨论】:
-
因为它是父级的
nth-child,而不是类的nth-child。 -
@Axel 谢谢。是否有使用 css 检查其在一组兄弟姐妹中的奇数/偶数位置的解决方案?
标签: html css css-selectors