如何使用SASS将数字转换为百分比? [英] How to convert a number to a percentage with SASS?
本文介绍了如何使用SASS将数字转换为百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张 930 像素 x 530 像素的地图.我想使用 mixin 将经纬度坐标转换为框内的顶部/左侧百分比值.
I have a map that is 930px x 530px. I want to use a mixin to convert the lat/long coords to top/left percentage values inside the box.
这是我目前所拥有的...
This is what i have so far...
@mixin latLong ($lat, $long) {
left: (($long + 180) * (930/360)) + %;
top: (($lat + 90) * (530/180)) + %;
}
我是这样用的...
&.m1 {@include latLong(-33.94628333, 151.2157139);}
这是吐出一个值,但它是在引号中,所以对css无效.我究竟做错了什么?谢谢.
This is spitting out a value, but it's in quotes, so it's invalid to css. What am I doing wrong? Thanks.
推荐答案
您想使用乘法来应用一个单位,而不是串联:
You want to use multiplication to apply a unit, rather than concatenation:
@mixin latLong ($lat, $long) {
left: (($long + 180) * (930/360)) * 1%;
top: (($lat + 90) * (530/180)) * 1%;
}
这篇关于如何使用SASS将数字转换为百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文