Именованные параметры миксинов в SASS
Mixins können benannte Parameter erhalten. Schauen wir uns das am folgenden Beispiel an:
@mixin active($color) {
border: {
color: $color;
style: solid;
}
}
p {
@include active($color: orange);
}
div {
@include active($color: green);
}
Ergebnis der Kompilation:
p {
border-color: orange;
border-style: solid;
}
div {
border-color: green;
border-style: solid;
}
Zusätzlich können Standardwerte für Parameter an Mixins übergeben werden:
@mixin active($color, $width: 2px) {
border: {
color: $color;
width: $width;
style: dotted;
}
}
p {
@include active(yellow);
}
div {
@include active(yellow, 4px);
}
Nach der Kompilation sehen wir:
p {
border-color: yellow;
border-width: 2px;
border-style: dotted;
}
div {
border-color: yellow;
border-width: 4px;
border-style: dotted;
}
Erzählen Sie, welches das Ergebnis der Kompilation des folgenden Codes sein wird:
@mixin super-button($color, $background-color, $border-radius) {
color: $color;
background-color: $background-color;
border-radius: $border-radius;
}
.active-button {
@include super-button($color: white, $background-color: red, $border-radius: 2px);
}
Erzählen Sie, welches das Ergebnis der Kompilation des folgenden Codes sein wird:
@mixin super-button($color, $background-color, $border-radius: 5px) {
color: $color;
background-color: $background-color;
border-radius: $border-radius;
}
.active-button {
@include super-button($color: white, $background-color: red);
}
Erzählen Sie, welches das Ergebnis der Kompilation des folgenden Codes sein wird:
@mixin super-button($color, $background-color: orange, $border-radius: 5px) {
color: $color;
background-color: $background-color;
border-radius: $border-radius;
}
.active-button {
@include super-button($color: white, $border-radius:3px);
}