【问题标题】:nth-child(even) always selecting dd, never dt (even and odd lines in dl)nth-child(even) 总是选择 dd,从不 dt(dl 中的偶数行和奇数行)
【发布时间】:2011-03-22 08:39:23
【问题描述】:

我正在尝试为定义列表提供表格外观,并希望借助一些 css3 选择器使偶数行的颜色与奇数行不同。

#specs dt:nth-child(even), #specs dd:nth-child(even) {
    background: blue;
}

这个 css 代码导致 dt 没有背景色,并且每个 dd 都被涂成蓝色。在我看来,渲染引擎实际上也在计算兄弟姐妹而不是选择的兄弟姐妹,导致每个 dt 都是奇数,每个 dd 都是偶数。

【问题讨论】:

    标签: html css css-selectors


    【解决方案1】:

    如果我理解正确,您可以使用 nth-of-type 选择器:

    #specs dt:nth-of-type(even), #specs dd:nth-of-type(even) {
        background: blue;
    }
    

    见:http://jsfiddle.net/5Zjqh/

    【讨论】:

      【解决方案2】:

      事情就是这样。如果你愿意,你可以试试“nth-child(4n+1)”

      【讨论】:

        猜你喜欢
        • 2014-12-17
        • 2013-07-01
        • 1970-01-01
        • 2016-02-29
        • 1970-01-01
        • 2011-07-08
        • 2012-01-01
        • 1970-01-01
        相关资源
        最近更新 更多