CSS :where() 伪类
:where() 伪类有助于在较长的 CSS 选择器列表中最小化较长的代码。它避免了重复,只需用一个选择器替换多个选择器。在 :where() 伪类中,您也可以覆盖。
句法:
class_Name :where(html-tages) html-tag {
/* CSS code */
}
没有 :where() 伪类的选择器:
.className li em,
.className section em,
.className p em {
// CSS code
}
带有 :where() 伪类的选择器:
className :where(li, section, p) em {
//CSS code
}
示例 1:
HTML
GeeksforGeeks
CSS The :where() pseudo-class
A computer science portal
for geeks.
Geeks classes an extensive
classroom programme.
HTML
GeeksforGeeks
CSS :where() pseudo-class
This is GeeeksforGeeks website
If it will not override, then
the background colour of this
text is purple
If it will override, then the
background colour of this text
is green
输出:
示例 2:很容易覆盖 :where() 伪类,如下例所示。
HTML
GeeksforGeeks
CSS :where() pseudo-class
This is GeeeksforGeeks website
If it will not override, then
the background colour of this
text is purple
If it will override, then the
background colour of this text
is green
输出:
浏览器支持:
- 火狐 78+
- Chrome 72(通过实验性网络平台功能启用它)