【问题标题】:LESS Nested PropertiesLESS 嵌套属性
【发布时间】:2017-11-29 07:53:55
【问题描述】:

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

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

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

【问题讨论】:

    标签: css sass less


    【解决方案1】:

    查看文档,似乎不可能。 但是您可以轻松地创建一个 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;
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-06
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多