1
我有,目前有兩種顏色的漸變一個mixin:如何在mixin中處理可變數量的參數?
@mixin gradient($color-start, $color-end) {
background-image: linear-gradient(90deg, $color-start 0%, $color-end 100%);
}
,我到處使用像這樣
.my-gradient {
@include gradient(blue, yellow)
}
,但現在我想修改混入(或將其轉換爲一個函數),可以採用兩個或三個參數作爲漸變。
像(僞代碼):
@mixin gradient($color-start, $color-end, $color-center) {
...if $color-center param exists...
background-image: linear-gradient(90deg, $color-start 0%, $color-center 50%, $color-end 100%);
...if $color-center param does not exist...
background-image: linear-gradient(90deg, $color-start 0%, $color-end 100%);
}
我不知道的處理這種情況的最好辦法。
這是否回答幫助? https://stackoverflow.com/a/9960403/5561605 – sol