【发布时间】:2017-12-18 10:47:27
【问题描述】:
我终于硬着头皮开始使用 SCSS。为什么我不早点这样做?无论如何,在整个项目中我都在使用水平线性渐变,所以我创建了这个 mixin:
@mixin linear-gradient($direction,$left-color,$right-color) {
background: $left-color; // For browsers that do not support gradients
background: -webkit-linear-gradient($direction,$left-color,$right-color); // Safari 5.1-6 note direction is opposite
background: -o-linear-gradient($direction,$left-color,$right-color); // Opera 11.1-12
background: -moz-linear-gradient($direction,$left-color,$right-color); // Fx 3.6-15
background: linear-gradient(to $direction,$left-color,$right-color); // Standard
}
这是一种享受,但是,您会注意到 webkit 前缀行仅使用 $direction。事实上,为了获得一致的结果,它应该与指定的方向相反。所以在webkit这一行中指定left的地方,方向其实是right。
我已经看到了将整体解决方案应用于背景渐变的更复杂的方法,但这对于我的项目来说似乎没有必要。
有人能告诉我如何正确地编写类似@if @else 语句的东西,它会自动将方向从左到右转换,反之亦然?
【问题讨论】: