Can anyone please tell me how to concatenate a var and a string in LESS so I don't have the space between them?
I have the following code:
.text(@size) {
font-size: @size + px;
line-height: (@size / 10) + em;
}
h1 {
.text(16)
}
What the LESS outputs is the following:
h1 {
font-size: 12 px;
line-height: 1.2 em;
}
I need to find a way to remove the spaces.
Thanks Pete
this is how I recently solved a similar problem.
The %("string", value) function simply format a string and so it take the %d inside the string and transform it in whatever is value. an example here: http://cdpn.io/hAbwl
Hope this can help.
U can use something like this:
But on lesscss.org is this: prior to less 1.3.1 a (~"@{name}") type of selector was supported. Support for this will be removed in the near future.
I think another way of solution is not possible.
I think the cleanest way (without string interpolation) is to add 0px to your variable, e.g.
@size + 0px
.In case any late-comers find this thread:
There is a built-in function for this:
So
font-size: unit(@size, px);
should result infont-size: 12px
. I tested it.http://lesscss.org/#reference
In a case you need to use it in combination with CSS function (eg. calc), here is one way:
Outputs:
Less replaces anything but values with spaces, so to convert units you add 0 of that unit. Just dont pass in a unit value.
Hope this helps someone else.