Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is calc not working with rem and px combined?

I tried the following style on a div but it is saying invalid css:

max-width: calc(24rem-13px);

The calc is using rem and px combined. If I remove the px part, then browser accepts the calc as valid style.

I am using latest Chrome.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You just need to add a space around the minus operator:

.test {
  background-color: gold;
  max-width: calc(24rem - 13px);
}
<div class="test">I have a max width</div>

It’s not working because without the space it could be interpreted as a negative value calc(24rem - -13px) for example

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading