嵌套 CSS 类

2024-02-28

我可以做如下的事情吗?

.class1{some stuff}

.class2{class1;some more stuff}

更新1:CSS 3 级嵌套有一个 CSS3 规范。目前它是一个草案。https://tabatkins.github.io/specs/css-nesting/ https://tabatkins.github.io/specs/css-nesting/

更新 2(2019):我们现在有了 CSSWG 编辑草稿https://drafts.c​​sswg.org/css-nesting-1/ https://drafts.csswg.org/css-nesting-1/

更新 3(2022 年):我们现在有了 W3C 第一个公共工作草案https://www.w3.org/TR/css-nesting-1/ https://www.w3.org/TR/css-nesting-1/

更新 4(2023 年):该功能现已在 Chrome 中提供caniuse.com/css-nesting https://caniuse.com/css-nesting

如果获得批准,语法将如下所示:

table.colortable {
  & td {
    text-align:center;
    &.c { text-transform:uppercase }
    &:first-child, &:first-child + td { border:1px solid black }
  }
  & th {
    text-align:center;
    background:black;
    color:white;
  }
}

.foo {
  color: red;
  @nest & > .bar {
    color: blue;
  }
}

.foo {
  color: red;
  @nest .parent & {
    color: blue;
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

嵌套 CSS 类 的相关文章

随机推荐