Using modulus in css calc function

Unfortunately, there is no more mention of the mod operator in recent specs. The calc() function allows mathematical expressions with addition (+), subtraction (-), multiplication (*), and division (/) to be used as component values. You may want to resort to using javascript to achieve such behaviour. var el = document.getElementById(‘element-id’); el.style.width = (100 % … Read more

Using calc() with tables

Tables have difficult rules about distributing the space of the columns because they distribute space dependent on the content of the cells by default. Calc (atm) just wont work with that. What you can do however is to set the table-layout attribute for the table to force the child td elements to get the exact … Read more

calc() not working within media queries

ANSWER EDITED AGAIN 21.03.2022: In the current version of the spec, using calc (or var) in media queries is NOT supported by the spec (as TylerH pointed out below). Properties sometimes accept complex values, e.g., calculations that involve several other values. Media features* only accept single values: one keyword, one number, etc. * Media features … Read more

CSS Calc alternative

Almost always box-sizing: border-box can replace a calc rule such as calc(100% – 500px) used for layout. For example: If I have the following markup: <div class=”sideBar”>sideBar</div> <div class=”content”>content</div> Instead of doing this: (Assuming that the sidebar is 300px wide) .content { width: calc(100% – 300px); } Do this: .sideBar { position: absolute; top:0; left:0; … Read more

Disable LESS-CSS Overwriting calc() [duplicate]

Using an escaped string (a.k.a. escaped value): width: ~”calc(100% – 200px)”; Also, in case you need to mix Less math with escaped strings: width: calc(~”100% – 15rem +” (10px+5px) ~”+ 2em”); Compiles to: width: calc(100% – 15rem + 15px + 2em); This works as Less concatenates values (the escaped strings and math result) with a … Read more

How do I debug CSS calc() value?

Is there a way to validate/highlight formulas errors? You need to check to see if you aren’t breaking any rules when defining your formula. Here it is from the specification: At each operator, the types of the left and right argument are checked for these restrictions. If compatible, the type resolves as described below (the … Read more