新的 CSS 伪类函数 :is() 和 :where()

Posted on 2022-08-15 14:39  书中枫叶  阅读(85)  评论(0编辑  收藏  举报

:is() 和 :where()

标题中的 <b> 标签进行颜色调整:

h1 > b, h2 > b, h3 > b, h4 > b, h5 > b, h6 > b {
  color: hotpink;
}

现在,我们可以使用 :is() 缩减代码并提高其可读性:

:is(h1,h2,h3,h4,h5,h6) > b {
  color: hotpink;
}


使用 :where()

:where(h1,h2,h3,h4,h5,h6) > b {
  color: hotpink;
}


:is() 和 :where() 组合使用

:is(.dark-theme, .dim-theme) :where(button,a) {
  color: rebeccapurple;
}
:is(h1,h2):where(.hero,.subtitle) {
  text-transform: uppercase;
}
.hero:is(h1,h2,:is(.header,.boldest)) {
  font-weight: 900;
}

Copyright © 2024 书中枫叶
Powered by .NET 8.0 on Kubernetes