6

我只是想知道是否可以通过对 CSS 代码应用变亮或变暗来改变 Less mixin 渐变的颜色?

这是较少的混合:

.css-gradient(@from: #20416A, @to: #3D69A5) {
    background-color: @to;
    background-image: -webkit-gradient(linear, left top, left bottom, from(@from),  to(@to));
    background-image: -webkit-linear-gradient(top, @from, @to);
    background-image: -moz-linear-gradient(top, @from, @to);
    background-image: -o-linear-gradient(top, @from, @to);
    background-image: -ms-linear-gradient(top, @from, @to);
    background-image: linear-gradient(top, @from, @to);
}

在 Less 文件中,我想做这样的事情:

#div {
    width:100px;
    height:100px;
    .css-gradient (darken, 10%);
}

不知道这是否可能,或者是否有其他方法我应该这样做。

4

2 回答 2

15

我会这样做:

.css-gradient(darken(#20416A,10%),darken(#3D69A5,10%))

当然你也可以这样做:

.css-gradient(@from: #20416A, @to: #3D69A5) {
    background-color: @to;
    background-image: -webkit-gradient(linear, left top, left bottom, from(@from),  to(@to));
    background-image: -webkit-linear-gradient(top, @from, @to);
    background-image: -moz-linear-gradient(top, @from, @to);
    background-image: -o-linear-gradient(top, @from, @to);
    background-image: -ms-linear-gradient(top, @from, @to);
    background-image: linear-gradient(top, @from, @to);
}
.css-gradient(darken,@amount: 10%, @from: #20416A, @to: #3D69A5){
    .css-gradient(darken(@from,@amount),darken(@to,@amount));
}

然后就叫它:

.css-gradient(darken,10%);

或者:

.css-gradient(#20416A, #3D69A5);

或者:

.css-gradient(darken,5%,#00ff00,#ff0000);
于 2012-06-06T20:40:51.687 回答
0

少混合:

.gradient(@dir: 0deg; @colors; @prefixes: webkit, moz, ms, o; @index: length(@prefixes)) when (@index > 0) {
    .gradient(@dir; @colors; @prefixes; (@index - 1));

    @prefix : extract(@prefixes, @index);
    @dir-old: 90 - (@dir);

    background-image: ~"-@{prefix}-linear-gradient(@{dir-old}, @{colors})";
    & when ( @index = length(@prefixes) ) {
        background-image: ~"linear-gradient(@{dir}, @{colors})";
    }
}

使用:.gradient(90deg, #FFAA64, #FFCD73);

于 2020-03-06T17:49:24.120 回答