如何在sass mixin中为每个属性添加值?

时间:2015-03-12 15:30:34

标签: css sass

我是Sass的新手,我正在使用下一个值

创建一个嵌套的运行
.heightAndWidth {
    height: 21px;
    width: 20px;
}

但我想扩展此规则并在特定类中添加10 px而不是21,31,但重用嵌套规则是否可能?我该怎么办?

1 个答案:

答案 0 :(得分:2)

抱歉,这是scss

@mixin heightAndWidth($px) {
  width : $px; 
  height : $px; 
}

.box { @include heightAndWidth(10px); }

这是sass

=widthAndHeight($px)
  width:    $px
  hight:    $px

.box
  +widthAndHeight(10px)

http://www.sass-lang.com/guide

你可以在这里找到文档。

$a = 100px; 
div {
    background: black;
    height:100px;
}
.one {
    width: $a;
    $a = $a+100;
}
.two {
   width: $a;
   $a = $a+100;
}
.three {
   width: $a;
   $a = $a+100; 
}