【问题标题】:Nested properties with common affix具有公共词缀的嵌套属性
【发布时间】:2014-02-14 08:00:25
【问题描述】:

在 SCSS 中,具有通用 前缀 的属性可以描述为嵌套属性。因此,就像在example 中一样,

.funky{
  font: 2px/3px{
    family: fantasy;
    size: 30em;
    weight: bold;
  }
}

编译为:

.funky{
  font: 2px/3px;
  font-family: fantasy;
  font-size: 30em;
  font-weight: bold;
}

我如何对具有共同词缀的属性做类似的事情?我怎样才能编写一个可以编译成这样的嵌套属性:

.funky{
  color: red;
  background-color: green;
  border-color: blue;
}

【问题讨论】:

    标签: css colors sass nested-properties


    【解决方案1】:

    Sass 没有这样的概念。你必须修补它或编写一个详细的 mixin 来完成它。

    @mixin color($background: null, $border: null, $font: null) {
        background-color: $background;
        border-color: $border;
        color: $font;
    }
    
    .foo {
        @include color($background: green, $font: red);
    }
    

    【讨论】:

    • $ 中的 @include color($background: green, $font: red); 看起来不太好。是否可以传递诸如哈希或关键字参数之类的东西?
    • 好的,我意识到 SASS 关键字参数需要$。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    相关资源
    最近更新 更多