gpt4 book ai didi

less - 对数值变量求反,并在LessCSS中添加 'px'

转载 作者:行者123 更新时间:2023-12-03 09:02:01 24 4
gpt4 key购买 nike

我想创建一个执行以下操作的函数:

.sprite-size (@width,@height,@x,@y) {
width:~'@{width}px';
height:~'@{height}px';
background: @sprites no-repeat -~'@{x}px' -~'@{y}px';
}
我想在 @x@y中传递一个正值,然后在输出中取反它们。对于给定的示例,上述LESS函数输出以下内容:
//LESS
.header-language-selection {
.sprite-size(44,21,312,0);
}

//Outputs CSS
.header-language-selection {
width: 44px;
height: 21px;
background: url('/Content/images/sprites.png') no-repeat - 312px - 0px;
}
如您所见,输出结果在 -px之间包含一个空格。有什么办法可以消除这个问题并实现我想要的?
我希望该行的输出为: background: url('/Content/images/sprites.png') no-repeat -312px -0px;

最佳答案

只需将1乘以所需的符号和单位即可。所以:

.sprite-size(@width, @height, @x, @y) {
width: @width*1px;
t: @height*1px;
background: @sprites no-repeat @x*-1px @y*-1px;
}

关于less - 对数值变量求反,并在LessCSS中添加 'px',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14384803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com