I wrote the following code in css. The purpose of the first line is to calculate the number of objects that can fit in one line based on the screen width and that calculated number is used in the second line to calculate the width of these objects.
:root{
--linkCount: calc(100vw / 200px);
--linkwidth: calc(230px + (100vw - 60px - (var(--linkCount) * (230px + 6px))) / var(--linkCount));
}
The problem is that the first calculation calc(100vw / 200px);
is not working. When I run this code on the website, the objects have the smallest width possible based the content (so basically width:auto;
) When I replace it with e.g. calc(5);
or 5;
it works. I already tried removing or adding spacing but no luck.
edit 1
Here a code snippet. The two variable are placed in the :root
https://jsfiddle.net/josvm9dw/
Can somebody explain to me why it is not working because I don't get it.