我想创建一个执行以下操作的函数:
.sprite-size (@width,@height,@x,@y) {
width:~'@{width}px';
height:~'@{height}px';
background: @sprites no-repeat -~'@{x}px' -~'@{y}px';
}
Run Code Online (Sandbox Code Playgroud)
我想通过一个正数值,@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;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,输出结果包含-和之间的空格px.有没有办法可以删除它并实现我想要的?
我希望该行的输出为: background: url('/Content/images/sprites.png') no-repeat -312px -0px;
Sco*_*ttS 58
只需乘以1你想要的符号和单位即可.所以:
.sprite-size(@width, @height, @x, @y) {
width: @width*1px;
height: @height*1px;
background: @sprites no-repeat @x*-1px @y*-1px;
}
Run Code Online (Sandbox Code Playgroud)
小智 8
你也可以试试这个:
.sprite-size (@width,@height,@x,@y) {
width: ~"@{width}px";
height: ~"@{height}px";
background: @sprites no-repeat @x*(-1px) @y*(-1px);
}
Run Code Online (Sandbox Code Playgroud)