如何计算 LESS CSS 中的百分比?
我想根据 LESS CSS 的父容器计算子容器(div 等)的宽度(以百分比表示)。
我正在使用 Ethan Marcotte 的论坛:目标/上下文=结果。
父容器:620px
子容器:140px
我正在使用这个计算:
div.child-container {
width: (140/620)*100%;
}
但是输出是:
div.child-container {
width: 0.2258064516129;
}
我想将小数点移动两位数并添加%,如下所示:
div.child-container {
width: 22.58064516129%;
}
非常感谢任何提示。
I would like to calculate the width of child-container (div etc) in percentages depending on the parent container with LESS CSS.
I am using the forumula by Ethan Marcotte: target / context = result.
Parent container: 620px
Child container: 140px
I am using this calculation:
div.child-container {
width: (140/620)*100%;
}
However the output is:
div.child-container {
width: 0.2258064516129;
}
I would like to move the decimal point two digits and add the %, like this:
div.child-container {
width: 22.58064516129%;
}
Any hints greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 LESS CSS 网站,您需要更改方程的顺序
应该是:
According to the LESS CSS website, you need to change the order of your equation
It should be:
也许当OP询问时,
percentage
函数不存在,但供将来参考我添加这个答案。Maybe the
percentage
function didn't exist when OP was asking but for future reference I add this answer.对于2022年,LESS 4.0和除法运算关注的是:
请参阅文档。
As for 2022, LESS 4.0 and division operator concerned:
See the docs.