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
  • 30,985
  • 5
  • 40
  • 52
Mark Cassar
  • 1,842
  • 4
  • 20
  • 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
  • 30,985
  • 5
  • 40
  • 52
ScottS
  • 71,703
  • 13
  • 126
  • 146
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
  • 30,985
  • 5
  • 40
  • 52
VyseExhale
  • 141
  • 1
  • 5