CSS选择器以反转选择

CSS选择器以反转选择,css,selector,Css,Selector,与反向选择器逻辑相比,使用:not()有什么优点或缺点?可能是在性能、安全性或浏览器支持方面,建议采用哪种方法 要么: .imageSlider img:not(:first-child) { display: none; } 或: 有时最好使用:而不是 <p class="my-paragraph"> <div class="something"></div> <div class="something-else"><

与反向选择器逻辑相比,使用
:not()
有什么优点或缺点?可能是在性能、安全性或浏览器支持方面,建议采用哪种方法

要么:

.imageSlider img:not(:first-child) {
  display: none;
}
或:


有时最好使用
:而不是

<p class="my-paragraph">
    <div class="something"></div>
    <div class="something-else"></div>
    <div class="an-other-thing"></div>
    <div class="an-other-thing"></div>
    <div class="last-one"></div>
</p>
而不是:

.my-paragraph div {
    display: none;
}

.my-paragraph div.an-other-thing {
    display: block;
}

在大多数情况下,较长的CSS意味着较长的执行时间

有时最好使用
:而不是

<p class="my-paragraph">
    <div class="something"></div>
    <div class="something-else"></div>
    <div class="an-other-thing"></div>
    <div class="an-other-thing"></div>
    <div class="last-one"></div>
</p>
而不是:

.my-paragraph div {
    display: none;
}

.my-paragraph div.an-other-thing {
    display: block;
}

在大多数情况下,更长的CSS意味着更长的执行时间。从2017年1月起,目前只有Safari浏览器支持:not选择器,全局浏览器支持率仅为11%。我不会在生产代码中使用它。

从2017年1月起,目前只有Safari浏览器支持:not选择器,而全局浏览器支持率仅为11%。我不会在生产代码中使用它。

您似乎混淆了(允许在
:not()中使用复杂选择器)
(只允许简单选择器,如问题中的代码所示)。基本支持覆盖率为98%+浏览器。您似乎混淆了(允许在
:not()中使用复杂选择器)
with(仅允许简单的选择器,如问题中的代码所示)。基本支持的浏览器覆盖率超过98%。