Is there a way to use variables in Less for the ~ operator, like ~“calc(100% - @spacing)”;

别等时光非礼了梦想. 提交于 2019-12-02 16:05:26

To disable the calculation which LESS does automatically when discovering a - between two numeric values but still being able to use variables, you can write one of the following:

1) Only escape the operator that triggers the calculation and use the variable like you normally do

@padding: 20px;
body {
    padding: calc(100% ~"-" @padding);
}

2) Escape the whole expression and interpolate the variable with the @{padding} notation

@padding: 20px;
body {
    padding: ~"calc(100% - @{padding})";
}

I prefer the second version, since it resembles javascript's template literals and looks a bit cleaner, but either way works just fine.

Both solutions disable the automatic Less calculation and compile to the correct result:

body {
  padding: calc(100% - 20px);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!