我尝试选择.container
中的所有元素,但不包括.Head
及其所有子元素(以及子元素的子元素,等等)。
有没有办法让所有的元素独立于它们的种类?类似于通配符*
// I know, this is not valid. What is the element that I can replace the (*)
.container *:not(:first-child) select {
background: yellow;
}
红色轮廓内的所有项目都应从选择器中排除。我该怎么做呢?
.container :not(:first-child) {
font-weight: bold;
font-style: italic;
background-color: yellow;
}
.Head {
border: 2px dashed red;
}
<div class="container">
<div class="Head" style="border: 2px dashed red;">
Target to exclude from the selector
<div>Target to exclude</div>
<div>Target to exclude</div>
</div>
<p>Target to select<p>
<ul>
<li>Target to select</li>
</ul>
<h1>Target to select</h1>
<p class="anotherparagraph">Target to select</p>
<span>Target to select</span>
</div>
发布于 2018-07-19 03:01:27
.container > *:not(.Head), .container > *:not(.Head) * { }
...should做这件事。
发布于 2018-07-19 03:11:45
您必须从CSS中的容器中排除.Head
类,如示例所示。
.container > :not(.Head){
font-weight: bold;
font-style: italic;
background-color: yellow;
}
.Head {
border: 2px dashed red;
}
<div class="container">
<div class="Head" style="border: 2px dashed red;">
Target to exclude from the selector
<div>Target to exclude</div>
<div>Target to exclude</div>
</div>
<p>Target to select<p>
<ul>
<li>Target to select</li>
</ul>
<h1>Target to select</h1>
<p class="anotherparagraph">Target to select</p>
<span>Target to select</span>
</div>
https://stackoverflow.com/questions/51408155
复制相似问题