LESS嵌套属性

3

出于好奇,想问一下:
在LESS中是否支持嵌套属性?因为SASS支持这个特性(嵌套属性)

div {
  background: {
    size: cover;
    color: green;
  }
}

TO

div {
  background-size: cover;
  background-color: green;
}
1个回答

0
从文档来看,似乎不可能实现。 但你可以很容易地创建一个类似的混合
.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;
  );
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接