Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Less, CSS3 calc() doesn't work correctly [duplicate]

Tags:

css

less

When I use this calc(100% + 20px) directly in Chromes and Firefox' Inspector it works fine and as shown.

However when I insert it into my less file it gets converted to 120%. What am I doing wrong?

like image 309
Morten Hjort Avatar asked Aug 17 '14 20:08

Morten Hjort


People also ask

How does the CALC () function work on values in CSS?

The calc() function takes a single expression as its parameter, with the expression's result used as the value. The expression can be any simple expression combining the following operators, using standard operator precedence rules: + Addition.

Is CSS calc slow?

Custom properties and calc are the same computational amount as any other property or relative value, respectively. In short: no more than large amounts of CSS would.

How do you write a calculator in CSS?

In the above code example, the calc() function is used to give the width value to the heading. Here , we have used the value of the parent which is set to 100% of the screen width by default. The calc(50% – 100px) means that the width of the heading will be equal to “50% of the width of the parent – 100 px”.

How do you calculate height in HTML?

To get the height or width of an element in pixels (including padding and borders), use the offsetHeight and offsetWidth properties of the object. These values are readonly.


1 Answers

Less will try to process all maths including 100% + 20px.

You could either set Strict Math on:

lessc -sm=on
lessc --strict-math=on

Or use a tilde-quote ~"100% + 20px" in order to prevent the statement from being processed by Less.

For instance:

.class {
    padding-left: calc(~"100% + 20px");
}
like image 197
Hashem Qolami Avatar answered Oct 25 '22 20:10

Hashem Qolami