Css 较少嵌套的属性

Css 较少嵌套的属性,css,sass,less,Css,Sass,Less,出于好奇: 嵌套属性是否可以在较少的时间内实现?由于SASS支持此功能() 到 看一下文档,这似乎是不可能的。 但是你可以很容易地创建一个mixin div { background: { size: cover; color: green; } } div { background-size: cover; background-color: green; } .setBackground( @color: green; @image: ''; @repea

出于好奇:
嵌套属性是否可以在较少的时间内实现?由于SASS支持此功能()


看一下文档,这似乎是不可能的。 但是你可以很容易地创建一个mixin

div {
  background: {
    size: cover;
    color: green;
  }
}
div {
  background-size: cover;
  background-color: green;
}
.setBackground( @color: green; @image: ''; @repeat: no-repeat; @position: center; @size: '' ) {
  background: @color @repeat @position;

  & when not ( @image = '' ) {
    background-image: @image;
  }

  & when not ( @size = '' ) {
    background-size: @size;
  }
}

div {
  .setBackground(
    @color: yellow;
    @image: url( some-image.png );
    @repeat: repeat;
    @size: cover;
  );
}