首页 文章

无法更改twitter bootstrap奇数表行的背景颜色

提问于
浏览
-1

我用Twitter Bootstrap css文件搅拌了一张 table . 该表的定义如下:

<table class="table table-striped table-bordered table-hover">
...
</table>

使用jQuery我在表行的按钮上添加了一个名为“.red-background”的类 .

.red-background
{
    background-color: red !important;
    color: white !important;
}

问题是代码在对行上工作正常,但不是奇怪的!我不知道为什么,但删除表的类“table-striped”和“table-hover”,一切正常 . “红色背景”类中定义的“颜色”规则有效,但奇数行上的“背景颜色”没有 .

2 回答

  • 0

    找到一个有效的答案here

    在CSS中添加一个专门覆盖条带化规则的类,并将其添加到其他CSS规则下 . 对于您的示例,这是标记 .

    table.table.table-striped tr.red-background td {
        background-color: red !important;
        color: white !important;
    }
    
  • 1

    使用此CSS类

    .table-striped tbody > tr:nth-child(2n+1) > td, .table-striped tbody > tr:nth-child(2n+1) > th {
        background-color: red !important;
        color: white !important;
    }
    

    希望能奏效 .

相关问题