Reader small image

You're reading from  Less Web Development Essentials (Second Edition)

Product typeBook
Published inApr 2015
Publisher
ISBN-139781783554072
Edition1st Edition
Tools
Right arrow
Author (1)
Bass Jobsen
Bass Jobsen
author image
Bass Jobsen

Bass Jobsen has been programming the web since 1995, ranging from C to PHP. He has a special interest in the processes between designer and programmer. He works on the accessibility of Bootstrap and his JBST WordPress starters theme. With over 5 years of experience with Bootstrap, Bass has been actively contributing to the community with his blogs and Git repos.
Read more about Bass Jobsen

Right arrow

Variable interpolation


In Less, variables can be used inside selector names, property names, URLs, and even import rules. The compiler applies string interpolation to replace the variable reference with its corresponding value.

Variables can be written with curly brackets around their name to prevent ambiguity. Take a look at the following Less code example:

@var: less;
.@{var} {
  property: ~"@{var}-5";
}

The preceding code will get compiled in CSS as follows:

.less {
  property: less-5;
}

Since Less v1.6, you can also use variable interpolation for properties. You can see this if you inspect the following Less code:

@property: width;
.fixed {
  @{property}: 100%;
  max-@{property}: 500px;
}

The preceding code will get compiled in CSS as follows:

.fixed {
  width: 100%;
  max-width: 500px;
}

In some situations, you will need quotes around the values; escaping these values will be explained in the next section. Variable interpolation can also be used to create variable variables, as can be seen in...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Less Web Development Essentials (Second Edition)
Published in: Apr 2015Publisher: ISBN-13: 9781783554072

Author (1)

author image
Bass Jobsen

Bass Jobsen has been programming the web since 1995, ranging from C to PHP. He has a special interest in the processes between designer and programmer. He works on the accessibility of Bootstrap and his JBST WordPress starters theme. With over 5 years of experience with Bootstrap, Bass has been actively contributing to the community with his blogs and Git repos.
Read more about Bass Jobsen