LESS CSS - 无法划分两个像素单位并返回无单位值
我想(暂时)删除变量 @baseLineHeight
和 @baseFontSize
的单位,以便我可以将它们除以得到相对行高。这是我尝试过的:
@baseFontSize: 12px;
@baseLineHeight: 18px;
font: @baseFontSize~"/"@baseLineHeight/@baseFontSize sans-serif;
生成以下错误:
Object #<Object> has no method 'toCSS' (Less::ParseError)
首选输出:
font: 12px/1.5 sans-serif;
I'd like to (temporarily) remove the units of my variables @baseLineHeight
and @baseFontSize
, so that I can divide them to get a relative line-height
. This is what I've tried:
@baseFontSize: 12px;
@baseLineHeight: 18px;
font: @baseFontSize~"/"@baseLineHeight/@baseFontSize sans-serif;
Generates the following error:
Object #<Object> has no method 'toCSS' (Less::ParseError)
Preferred output:
font: 12px/1.5 sans-serif;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
同时似乎有一个函数可以做到这一点:
http://lesscss.org/functions/#misc-functions-unit
这里评论中的代码,只是为了完整性。 (感谢 cfx)。
Meanwhile there seems to be a function for that:
http://lesscss.org/functions/#misc-functions-unit
Here the code from the comment, just for completeness. (thanks to cfx).
我错过了文档中有关 JavaScript 评估的部分。这似乎解决了我的问题:
I missed the part of the documentation regarding JavaScript evaluation. This seems to solve my problem:
其他答案似乎并没有实际作用。
根据 LESS 文档,
unit()
函数 将删除或更改维度的单位。由于该函数仅接受单个维度作为参数(以及可选参数),因此您将使用以下内容:因为 严格数学,您会注意到上面的行可能需要用括号括起来,以便实际计算数学。
上面的 LESS 将输出以下所需的结果:
The other answers don't seem to actually work.
According to the LESS documentation, the
unit()
function will remove or change the unit of a dimension. Since the function only accepts a single dimension as a parameter (and an optional parameter), you would use the following:Because of strict math, you will notice that the line above may need to be wrapped in parenthesis so that the math is actually evaluated.
The LESS above will output the following, desired results: