Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate string and var less css

Tags:

css

less

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

like image 626
Peter J Harrison Avatar asked Oct 04 '12 09:10

Peter J Harrison


People also ask

How do you concatenate strings and variables?

In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.

Can you use += for string concatenation?

Concatenation is the process of combining two or more strings to form a new string by subsequently appending the next string to the end of the previous strings. In Java, two strings can be concatenated by using the + or += operator, or through the concat() method, defined in the java. lang. String class.

How do I combine strings and numbers?

If you want to concatenate a string and a number, such as an integer int or a floating point float , convert the number to a string with str() and then use the + operator or += operator.


1 Answers

In case any late-comers find this thread:

There is a built-in function for this:

unit(@dimension, [@unit: ""]);

So font-size: unit(@size, px); should result in font-size: 12px. I tested it.

http://lesscss.org/#reference

like image 123
Mike Avatar answered Sep 21 '22 07:09

Mike