31

I would like to create a function which does the following:

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

I would like to pass a positive value, in @x and @y and then negate them in the output. The above LESS function outputs the following for the given example:

//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;
}

As you can see the output result includes a space between the - and the px. Is there any way where one can remove this and achieve what I want?

I want the output of that line to be: background: url('/Content/images/sprites.png') no-repeat -312px -0px;

Raine Revere
  • 27,477
  • 4
  • 33
  • 48
Mark Cassar
  • 1,792
  • 4
  • 18
  • 27

2 Answers2

60

Just multiply by 1 in the sign and units you want. So:

.sprite-size(@width, @height, @x, @y) {
  width: @width*1px;
  t: @height*1px;
  background: @sprites no-repeat  @x*-1px  @y*-1px;
}
Raine Revere
  • 27,477
  • 4
  • 33
  • 48
ScottS
  • 70,348
  • 13
  • 121
  • 143
10

You can also try this:

.sprite-size (@width,@height,@x,@y) {
  width: ~"@{width}px";
  height: ~"@{height}px";
  background: @sprites no-repeat  @x*(-1px)  @y*(-1px);
}
Raine Revere
  • 27,477
  • 4
  • 33
  • 48
VyseExhale
  • 141
  • 1
  • 5