更少的嵌套属性

LESS Nested Properties

出于好奇:
LESS 中可以嵌套属性吗?由于 SASS 支持此功能 (Nested Properties)

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

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

看文档,好像不可以。 但是你可以轻松地创建一个 mixin that works similar.

.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;
  );
}