我是sass的新手,目前正在探索它。我想尝试使用mixin,但是当我尝试它时,它却无法正常工作。这是代码:
@mixin container($radius, $width, $height, $bg, $color) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
$width: $width;
$height: $height;
$bg: $bg;
$color: $color;
margin: 0 auto;
}
.container {
@include container(10px, 80%, 700px, $white, $dark-grey)
}
所以我有一个div和class容器,想将mixin放在那里,但是它不起作用。有人可以帮忙吗?
答案 0 :(得分:2)
这个?
$white: #fff;
$dark-grey: #666;
@mixin container($radius, $width, $height, $bg, $color) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
width: $width;
height: $height;
background: $bg;
color: $color;
margin: 0 auto;
}
.container {
@include container(10px, 80%, 700px, $white, $dark-grey)
}
答案 1 :(得分:1)
您的变量看起来有点混乱
这应该有效:
@mixin container($radius, $width, $height, $bg, $color) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
width: $width; // <= here
height: $height; // <= here
background-color: $bg; // <= here
color: $color;
margin: 0 auto;
}
.container {
@include container(
10px,
80%,
700px,
white, // <= here
darkgrey // <= here
)
}
CSS
.container {
border-radius: 10px;
width: 80%;
height: 700px;
background-color: white;
color: darkgrey;
margin: 0 auto;
}