我在表中有几个<th>
标记,除非第一个标记,否则我想更改其颜色。我尝试了css :not
选择器,但是将子字符串选择器放到里面时,它不起作用。仅当我直接放置元素的id
时它才起作用。
但是,我想使其更具动态性(例如,无需每次都更改id
)。我应该怎么做?
//This is not working
th[id*="header"]:not(th[id*="header0"])
//This is working
th[id*="header"]:not(#header0)
/*
th[id*="header"]:not(th[id*="header0"]) {
color: red;
}
*/
th[id*="header"]:not(#header0) {
color: red;
}
<table>
<tr>
<th id="header0">Header0</th>
<th id="header1">Header2</th>
<th id="header2">Header3</th>
<th id="header3">Header4</th>
<th id="header4">Header5</th>
<th id="header5">Header6</th>
</tr>
</table>
最佳答案
我怀疑您正在寻找这样的东西
th[id^="header"]:not([id$="0"]) {
color: red;
}
<table>
<tr>
<th id="header0">Header0</th>
<th id="header1">Header2</th>
<th id="header2">Header3</th>
<th id="header3">Header4</th>
<th id="header4">Header5</th>
<th id="header5">Header6</th>
</tr>
</table>
其中
th[id^="header"]:not([id$="0"])
读为:ID为“ header”但不以“ 0”结尾的第th个元素。