I understand how to use variables in CSS. They have helped heaps with speeding up my work flow for my clients' sites.
I have noticed on more than a few occasions I would write down variables with a number next to it to assign to a particular color or look because there is no array system in place. I ended up creating a quasi-array so to speak.
Like this
--c1: color:#ddd; //link color
--c2: color:#aaa; //quote color
--c3: color:#444; //body text
Is it possible to do something like this in CSS?
--c new array (color:#ddd, color:#aaa, color:#444);
Then call array
arr(--c,3);
instead of
var(--c3);
I get that CSS is not a OOP, but it would be nice to be able to handle data like this, especially if I can extend it across two dimensions. I also understand this may be a pointless exercise in theory as typing --c3 is faster than doing --c,3 or even --c[3]. Food for thought.
An array is a variable containing multiple values. Any variable may be used as an array. There is no maximum limit to the size of an array, nor any requirement that member variables be indexed or assigned contiguously.
Moreover, these have either a global scope or a local scope and can be accessed using the var() function. You can avoid writing down repeated CSS values by using these variables, furthermore, these are easier to understand. It is also possible to override CSS variables with one another.
CSS variables can be used in HTML's style attribute. You can choose to set the value of your variables inline, and they'll still work as expected. CSS variables are case-sensitive.
CSS variables have access to the DOM, which means that you can create variables with local or global scope, change the variables with JavaScript, and change the variables based on media queries. A good way to use CSS variables is when it comes to the colors of your design.
Properties in CSS cannot be grouped in arrays in the way you describe. This includes custom properties. Preprocessors such as Sass and LESS have maps and lists, but the way custom properties work (see section 3 of the spec) means it's not possible to group them and index off of them using the same syntax found in preprocessors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With