Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect vh calculations #3269

Closed
justinpombrio opened this issue Jul 5, 2018 · 3 comments
Closed

Incorrect vh calculations #3269

justinpombrio opened this issue Jul 5, 2018 · 3 comments

Comments

@justinpombrio
Copy link

The following calculation:

100vh - 50px

is done incorrectly. On my laptop (Macbook with retina display; chrome), it comes out to 300px when it should be 550px.

In more detail, here's a table of the size written in less, and the actual size as reported by Chrome's inspector (which matches what I see):

Specified Size   Actual Size
100vh            600px
100vh-50px       300px
100vh-10px       540px
300px            300px

(I rounded some numbers slightly.)

@matthew-dean
Copy link
Member

matthew-dean commented Jul 5, 2018

There's not enough information here. What is your input .less, and what is your .css output vs. your expected output? Also, include your Less version. Is this written in a calc()? What is the context for this expression?

@justinpombrio
Copy link
Author

Input:

.aclass {
  height: 100vh - 50px;
}

Output:

.aclass {
  height: 50vh;
}

Expected output: either css that does this computation, or an error if no such css exists.

Less does the same thing when the context of the expression is the definition of a variable (e.g. @height: 100vh - 50px;), which was the context I originally encountered it in. Splitting the computation across multiple variables or adding parentheses does not help.

Both versions 3.0.1 and 1.6.3.

@matthew-dean
Copy link
Member

@justinpombrio

You may be confused. First, there's not any such valid CSS value as height: 100vh - 50px;, so trying to produce that as output won't get you anywhere. What you want is: height: calc(100vh - 5px);. As of Less 3.5, operations in calc() are not touched.

As far as elsewhere, the operation as you reported it is working as designed. How math is treated in Less could always be improved. (See: #1880) But it's currently working as expected. That is, in general, Less ignores units in expressions, with the exception being calc() or using strictUnits: true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants