So I've been experimenting with CSS variables just to work with basic math, and I have the following JSFiddle (replication of code below): http://jsfiddle.net/eliseo_d/ry792Lnp/7/
:root {
--a: 51;
--b: 32;
}
#test_add:before {
color: red;
counter-reset: add_res calc(var(--a) + var(--b));
content: counter(add_res);
}
#test_sub:before {
color: blue;
counter-reset: sub_res calc(var(--a) - var(--b));
content: counter(sub_res);
}
#test_mul:before {
color: orange;
counter-reset: mul_res calc(var(--a) * var(--b));
content: counter(mul_res);
}
#test_div:before {
color: green;
counter-reset: div_res calc(var(--a) / var(--b));
content: counter(div_res);
}
<div id="test_add"></div>
<div id="test_sub"></div>
<div id="test_mul"></div>
<div id="test_div"></div>
The results for the addition, subtraction and multiplication DIVs is correct, but I've had trouble getting the division DIV to work. Is there some special thing that must be done with the CSS variables for this to work?
Also, if I were to replace 51 with 5.1 and 32 with 3.2, the results for all of them also end up as zero... Is there any way that CSS Variables can work with decimals? Please note: I don't want to work with SASS or LESS or any other preprocessor here, I'm trying to investigate the potential I have with CSS variables on their own...
Thanks in advance...
INT(51/32) = 1if my math isn't mistaken?contentcan only be of typeintegerthus when doing a division, it might be a float, and will print0