Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何覆盖tr:n个子项(2n)?_Css - Fatal编程技术网

Css 如何覆盖tr:n个子项(2n)?

Css 如何覆盖tr:n个子项(2n)?,css,Css,站点范围的样式表具有以下形式的指令 #outerdiv tr:nth-child(2n) { background-color: #cccccc; } 我想为div#innerdiv中包含的表覆盖它,而div中又包含了outerdiv 我发现唯一有效的方法是: #innerdiv tr:nth-child(2n) { background-color: #ffffff; } 这在我看来过于具体,可能非常脆弱 是否有其他方法可以撤销站点范围的指令?或者,是否有方法为#inner

站点范围的样式表具有以下形式的指令

#outerdiv tr:nth-child(2n) {
    background-color: #cccccc;
}
我想为div
#innerdiv
中包含的表覆盖它,而div
中又包含了outerdiv

我发现唯一有效的方法是:

#innerdiv tr:nth-child(2n) {
    background-color: #ffffff;
}
这在我看来过于具体,可能非常脆弱

是否有其他方法可以撤销站点范围的指令?或者,是否有方法为
#innerdiv
中的所有表行指定背景色

FWIW,以下情况不起作用:

#innerdiv tr {
    background-color: #ffffff; !important;
}
试试这个

#innerdiv tr {
    background-color: #ffffff !important;
}
试试这个

#innerdiv tr {
    background-color: #ffffff !important;
}

根据表的嵌套方式,如果第一个表是
#outerdiv
的直接子表,则可以使用以下代码:

table tr {
    background-color: #fff
}
#outerdiv > table tr:nth-child(2n) {
    background-color: #cccc;
}

根据表的嵌套方式,如果第一个表是
#outerdiv
的直接子表,则可以使用以下代码:

table tr {
    background-color: #fff
}
#outerdiv > table tr:nth-child(2n) {
    background-color: #cccc;
}
背景色:#ffffff!重要的
背景色:#ffffff!重要的尝试此选择器:
#innerdiv>tr{背景色:#ffffff;}
它是
背景色:#ffffff!重要的
背景色:#ffffff!重要的尝试此选择器:
#innerdiv>tr{背景色:#ffffff;}