从 CSS 中的所有选择器中排除 class
Exclude a class from all of the selectors in CSS
首先抱歉我的英语不好。
我想从 CSS.
中的所有选择器中排除 class
我需要使用类似
的东西
(h1, h2, h3, h4, ..., p, span, a, ...):not(.exclude){
font-family: arial;
}
而不是:
h1:not(.exclude), h2:not(.exclude), ..., a:not(.exclude){
font-family: arial;
}
使用 CSS4 :is
selector. You can watch out for the browser support here: https://caniuse.com/?search=is 是可行的,但在现代 Web 开发人员的术语中,您可以安全地使用它。
:is(h1,h2,h3):not(.exclude) {
background: #bada55;
color: #565656;
padding: 10px;
}
<h1 class="exclude">
Excluded
</h1>
<h2 class="include">
Included
</h2>
<h3 class="exclude">
Excluded
</h3>
上面的代码是这样的
h1:not(.exclude), h2:not(.exclude), h3:not(.exclude) { Properties... }
你也可以使用 :where
做同样的事情:
:where(h1,h2,h3):not(.exclude) {
background: #bada55;
color: #565656;
padding: 10px;
}
<h1 class="exclude">
Excluded
</h1>
<h2 class="include">
Included
</h2>
<h3 class="exclude">
Excluded
</h3>
*:not(.exclude) {
font-family: arial;
}
会给所有字体系列 arial 除了带 class .exclude 的元素,但我不确定这是否是你的意思。
首先抱歉我的英语不好。 我想从 CSS.
中的所有选择器中排除 class我需要使用类似
的东西(h1, h2, h3, h4, ..., p, span, a, ...):not(.exclude){
font-family: arial;
}
而不是:
h1:not(.exclude), h2:not(.exclude), ..., a:not(.exclude){
font-family: arial;
}
使用 CSS4 :is
selector. You can watch out for the browser support here: https://caniuse.com/?search=is 是可行的,但在现代 Web 开发人员的术语中,您可以安全地使用它。
:is(h1,h2,h3):not(.exclude) {
background: #bada55;
color: #565656;
padding: 10px;
}
<h1 class="exclude">
Excluded
</h1>
<h2 class="include">
Included
</h2>
<h3 class="exclude">
Excluded
</h3>
上面的代码是这样的
h1:not(.exclude), h2:not(.exclude), h3:not(.exclude) { Properties... }
你也可以使用 :where
做同样的事情:
:where(h1,h2,h3):not(.exclude) {
background: #bada55;
color: #565656;
padding: 10px;
}
<h1 class="exclude">
Excluded
</h1>
<h2 class="include">
Included
</h2>
<h3 class="exclude">
Excluded
</h3>
*:not(.exclude) {
font-family: arial;
}
会给所有字体系列 arial 除了带 class .exclude 的元素,但我不确定这是否是你的意思。