【发布时间】: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 编译器会将引号内的值简单地视为文本而不是变量。