LESS: Subtract from variable

cusejuice picture cusejuice · Jul 2, 2013 · Viewed 22.9k times · Source

Using LESS, how can I subtract values with "px" at the end of the variable. I have the following variable:

@bpMobile: 600px

What I want to do is subtract this by 1px

@media only screen and (max-width: @bpMobile - 1px ) {
}

How can I achieve this with LESS?

Answer

Coreus picture Coreus · Oct 27, 2014

Sorry for answering this late, but I had this very problem and it seems LESS is picky about the spacing. You also need () around your calculation.

This will not work:

@media screen and (max-width: (@widthSmall-2)) { }

However, this will (notice the space between the variable and the digit):

@media screen and (max-width: (@widthSmall - 2)) { }