CSS3 calc(100%-88px) not working in Chrome

Google ChromeCss

Google Chrome Problem Overview


I noticed that my usage of the CSS3 calc() function as the unit for width is not working in the latest version of Chrome.

In the Chrome Developer tools, the rule with calc() has a strikethrough through it and an exclamation mark in a yellow triangle to the left of it. This is signaling that the property or value is not recognized.

How do I get it to work in modern browsers? Because it is a value and not a property, where do the vendor prefixes go?

Update:

When I say it doesn't work, I mean that Chrome Dev Tools is saying that it is not recognizing my usage of it width: calc(100%-88px);. How do I know it is not recognizing it? Because of the strikethrough and the yellow triangle icon next to the style rule in chrome dev tools.

Google Chrome Solutions


Solution 1 - Google Chrome

The problem in the question was caused by the lack of space around the subtraction operator.

> Note that the grammar requires spaces around binary ‘+’ and ‘-’ > operators. The ‘*’ and ‘/’ operators do not require spaces.

https://www.w3.org/TR/css3-values/#calc-syntax

I speculate that this is to make clear the differentiation between operators and signed numbers.

Bad: calc(100%-88px)
Good: calc(100% - 88px)


> How do I know it is not recognizing it? Because of the strikethrough > and the yellow triangle icon next to the style rule in chrome dev > tools.

A property that is struck in when viewed in Chrome's developer tools may be valid but overridden; however, a property struck through and with a warning triangle icon next to it is invalid.


Other Notes

  • Chrome has supported calc() for quite some time (confirmed on OSX and Windows).
  • Chrome may not support viewport units such as vh/vw inside calc(). As of late 2014, there is activity on implementing this, but the related bug is still open.
  • In my testing, Safari will support calc() with the -webkit vendor prefix on OSX but not Windows.
  • IE9+ supports calc() with no vendor prefix.
  • FF supports calc() with no vendor prefix.

Solution 2 - Google Chrome

Use -webkit prefix and spaces around the operator

width: -webkit-calc(100% - 88px);
width: -moz-calc(100% - 88px);
width: calc(100% - 88px);

Solution 3 - Google Chrome

I struggled with calc property a bit and only below approach worked.

-webkit-calc(~'100% - 40px'); // good: result 395px (in my application)

every above suggestions like:

-webkit-calc(100% - 40px); // bad: result 60%

ended up with wrong calculation like 60%.

Solution 4 - Google Chrome

I had to do something like this in Chrome to get it working...

calc(100vh - 88px);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIrfan MirView Question on Stackoverflow
Solution 1 - Google ChromeTim M.View Answer on Stackoverflow
Solution 2 - Google ChromeTamil Selvan CView Answer on Stackoverflow
Solution 3 - Google ChromeTomasz CzechowskiView Answer on Stackoverflow
Solution 4 - Google ChromeMichaelView Answer on Stackoverflow