gpt4 book ai didi

css - 如何否定CSS中的所有 child ?

转载 作者:太空宇宙 更新时间:2023-11-03 20:07:33 25 4
gpt4 key购买 nike

我需要选择所有 <div>页面上的 s,a 的所有子项除外 div ID 为 do-not-select .我当前的选择器是:

div:not(#do-not-select *)

但是,它不起作用,因为 :not运算符不允许复杂的选择器。手动指定所有 child

div:not(#child1):not(#child2):not(#child3)...

不是一个选项,因为它们太多了。在当前的 CSS3 限制下,我该如何编写这样的选择器?

编辑:我只能使用一个选择器(我不能让一个选择器以所有 div 为目标,而另一个以特定 div 的所有 child 为目标,以否定)

最佳答案

我会这样做:

div:not(#do-not-select) * { ... }

它选择除 ID 为 #do-not-select

的所有 DIV 的所有子项

* {
border: 1px solid red;
padding: 3px;
}

div:not(#do-not-select) * {
background-color: green;
}
<div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div id="do-not-select">
<div>4</div>
<div>5</div>
<div>6</div>
</div>

关于css - 如何否定CSS中的所有 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com