【发布时间】:2016-06-25 01:17:38
【问题描述】:
我有一种情况,需要将带有浅黄色背景的紫色字体颜色样式应用于具有RadDiv 类的 div 之外的所有 div。
这意味着所有嵌套在 div 中的类为 RadDiv 的 div 都应该被排除。
我尝试使用:not 选择器,如下所示,但它不起作用。 Demo of my situation
问题:如何指定:not 选择器以排除具有RadDiv 类的div 以及该div 内的所有嵌套div?
:not 选择器不起作用
div:not(.RadDiv) div {
background-color:lightyellow;
color:purple;
}
我尝试过的完整代码
<div>This is a div </div>
<div class="RadDiv newDiv outerDiv">
<div class="header">
This is the header
</div>
This is an outer div
<div class="alert highlight">
This div stands out
</div>
<div class="footer disclaimer">
This is the footer part
</div>
<table>
<tr>
<td>
<div>This is div inside a table element</div>
</td>
</tr>
</table>
</div>
<div id="div1">This is div1</div>
<div id="div2">This is div2</div>
<style>
div:not(.RadDiv) div {
background-color:lightyellow;
color:purple;
}
.outerDiv {
border:1px solid red;
font-family:Arial;
}
.footer {
color:lightgray;
font-size:small;
font-style:italic;
}
.header {
font-weight:bold;
}
【问题讨论】:
-
试试这个:
div:not(.RadDiv div) -
我刚试了下还是不行。
标签: html css css-selectors