较少的嵌套属性

时间:2017-06-26 12:57:28

标签: css sass less

出于好奇:
是否可以使用嵌套属性?由于SASS支持此功能(Nested Properties

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

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

1 个答案:

答案 0 :(得分:0)

查看文档,似乎不可能。 但您可以轻松创建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;
  );
}
相关问题