我需要将百分比值(51%)转换为数字(0.51)
这样做的最佳方式是什么?
我的小片段
// Gradients
#gradient {
.vertical-gloss(@startColor: #555, @endColor: #333, @firstColorStop:50%, @secondColorStart:51%) {
background-image: linear-gradient(bottom, @startColor @firstColorStop, @endColor @secondColorStart);
background-image: -o-linear-gradient(bottom, @startColor @firstColorStop, @endColor @secondColorStart);
background-image: -moz-linear-gradient(bottom, @startColor @firstColorStop, @endColor @secondColorStart);
background-image: -webkit-linear-gradient(bottom, @startColor @firstColorStop, @endColor @secondColorStart);
background-image: -ms-linear-gradient(bottom, @startColor @firstColorStop, @endColor @secondColorStart);
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.5, @startColor), color-stop(0.51, @startColor));
background-repeat: repeat-x;
}
}
答案 0 :(得分:6)
unit
function将50%
转换为50。为了便于阅读,我使用了一个辅助变量,如下所示:
.vertical-gloss(@startColor: #555, @endColor: #333, @firstColorStop:50%, @secondColorStart:51%) {
@firstColorStopPerc: (unit(@firstColorStop) / 100);
@secondColorStopPerc: (unit(@secondColorStart) / 100);
/* ... skipped non-relevant pieces ... */
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(@firstColorStopPerc, @startColor), color-stop(@secondColorStopPerc, @startColor));
background-repeat: repeat-x;
}