【问题标题】:Mixins Gradient for IE8IE8 的 Mixins 渐变
【发布时间】:2015-10-17 13:13:03
【问题描述】:

我正在尝试为渐变制作一些 LESS Mixin,以便在 IE8 中使用,我知道我可以像这样在 IE8 中使用渐变

filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */

这是 juwt 示例,但我需要制作一些自定义 mixin 来为 IE8 创建,这就是我拥有的 CSS

 background-image: linear-gradient(bottom, rgba(0,0,0, 0) 50%, rgba(255,255,255, 0.08) 0%);
    background-image: -o-linear-gradient(bottom, rgba(0,0,0, 0) 50%, rgba(255,255,255, 0.08) 0%);
    background-image: -moz-linear-gradient(bottom, rgba(0,0,0, 0) 50%, rgba(255,255,255, 0.08) 0%);
    background-image: -webkit-linear-gradient(bottom, rgba(0,0,0, 0) 50%, rgba(255,255,255, 0.08) 0%);
    background-image: -ms-linear-gradient(bottom, rgba(0,0,0, 0) 50%, rgba(255,255,255, 0.08) 0%);

我需要修改我创建的 LESS mixins

.gradient (@startColor: #eee, @endColor: white) {
    background-color: @startColor;
    background: -webkit-gradient(linear, left top, left bottom, from(@startColor), to(@endColor));
    background: -webkit-linear-gradient(top, @startColor, @endColor);
    background: -moz-linear-gradient(top, @startColor, @endColor);
    background: -ms-linear-gradient(top, @startColor, @endColor);
    background: -o-linear-gradient(top, @startColor, @endColor);
}

为了支持 IE8 :)

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='@startColor', endColorstr='@endColor',GradientType=0 ); /* IE6-9 */

但问题就在这里 '@startColor'

括号内不识别变量

【问题讨论】:

  • 您需要像startColorstr='@{startColor}' 一样使用它,而不是startColorstr='@startColor'(注意花括号)。当您不使用花括号时,Less 编译器会将引号内的值简单地视为文本而不是变量。

标签: css less mixins


【解决方案1】:

传统的 LESS 编译器不会接受 filter 属性,会抛出错误。你也可以简单地使用 LESS Escaping 来解决这个问题。您需要做的就是在渐变中添加以下行,它应该可以正常工作。

filter: ~”progid:DXImageTransform.Microsoft.gradient(startColorstr='@{startColor},
endColorstr='@{endColor})”;

这一行将在代码中出现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2013-04-12
    • 2011-05-25
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多