我想将green
background
与段与类和red
一个应用于其他所有段落。我已经完成了一半,但仍在努力处理空类 class=""
:
p {background:green}
#test p:not([class]) {
background: red;
color: #fff;
}
<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>
有人知道吗?
答案 0 :(得分:6)
你可以使用这样的空类来定位p
......
p[class=""] {
...
}
body {
font-weight: 700;
}
p {
background: green
}
#test p:not([class]),
#test p[class=""] {
background: red;
color: #fff;
}
<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>
答案 1 :(得分:1)
我使用了#test p [class =“”]我希望这就是你想要的。
body{
font-weight:700;
}
p{background:green}
#test p:not([class]) {
background:red;
color:#fff;
}
#test p[class=""]{
background:red;
color:#fff;
}