Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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
Html 有条件地重写表上的CSS类_Html_Css - Fatal编程技术网

Html 有条件地重写表上的CSS类

Html 有条件地重写表上的CSS类,html,css,Html,Css,我有一张桌子,上面装饰着以下班级: <table class="table table-striped table-borderless nowrap"> 通过这种方式自定义CSS 对于引导4 .table-striped tbody tr:not(.alert-primary):nth-of-type(odd) { background-color: rgba(0, 0, 0, 0.05); } 对于Bootstrap 3.7 .table-striped>tbody

我有一张桌子,上面装饰着以下班级:

<table class="table table-striped table-borderless nowrap">

通过这种方式自定义CSS

对于引导4

.table-striped tbody tr:not(.alert-primary):nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.05);
}
对于Bootstrap 3.7

.table-striped>tbody>tr:not(.alert-primary):nth-of-type(odd) {
    background-color: #f9f9f9;
}
你可以用

.table-striped tbody tr.alert.alert-primary:nth-of-type(odd) {
  background-color:red !important;
}

请注意,我在猜测,因为您还没有发布代码片段。

我想问题是
在哪个类中它说了什么
。也许您应该只使用jsfiddle或codepen来绘制一个工作示例,您在F12中看到该类添加了什么吗<代码>警报主警报
您有引导脚本吗?
可能有问题。表格带条纹的tbody tr:n类型(奇数)
具有
0-0-2-2
的特异性,而
则具有
的特异性。警报
。警报主警报
只是
0-0-1-0
。您可能需要
!重要信息
或类似信息。这是一种工作方式。这会使奇数行变为红色,但我希望警报主对象所在的行仍从表元素中的类中获取其背景。最好覆盖引导样式,而不是编辑它们-否则,如果需要升级,则必须记住已编辑的样式并再次编辑它们(假设这是引导-看起来像是)这是引导。我没有编辑它们,而是将它们添加到一个单独的CSS文件中。我将代码放在文件中,在我的问题中添加了一个图像,显示它是如何处理的。你是否将我的CSS放在你的文件中?是的,与你发布的完全一样
.table-striped tbody tr:not(.alert-primary):nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.05);
}
.table-striped>tbody>tr:not(.alert-primary):nth-of-type(odd) {
    background-color: #f9f9f9;
}
.table-striped tbody tr.alert.alert-primary:nth-of-type(odd) {
  background-color:red !important;
}