我想套用green background到段落与类和red一个所有其他人.我已经完成了一半,但仍在努力解决空课 class="":
p {background:green}
#test p:not([class]) {
background: red;
color: #fff;
}Run Code Online (Sandbox Code Playgroud)
<div id="test">
<p>This should be red</p>
<p class="abc">This should be green</p>
<p class="newname">This should be green</p>
<p class="">This should be red</p>
<p class="anothername">This should be green</p>
<p>This should be red</p>
<p class="">This should be red</p>
</div>Run Code Online (Sandbox Code Playgroud)
有人知道吗?
您可以p使用像这样的空类来定位...
p[class=""] {
...
}
Run Code Online (Sandbox Code Playgroud)
body {
font-weight: 700;
}
p {
background: green
}
#test p:not([class]),
#test p[class=""] {
background: red;
color: #fff;
}Run Code Online (Sandbox Code Playgroud)
<div id="test">
<p>This should be red</p>
<p class="abc">This should be green</p>
<p class="newname">This should be green</p>
<p class="">This should be red</p>
<p class="anothername">This should be green</p>
<p>This should be red</p>
<p class="">This should be red</p>
</div>Run Code Online (Sandbox Code Playgroud)