3 ms·
I'm not taking sides yet, but . . . "why CSS needs no variables" http://meiert.com/en/blog/20090401/why-css-needs-no-variables/ http://meiert.com/en/blog/2009
by klochner 17y ago
I'm not taking sides yet, but . . .
"why CSS needs no variables"
http://meiert.com/en/blog/20090401/why-css-needs-no-variables/ http://meiert.com/en/blog/20090401/why-css-needs-no-variable...
- r0s 17y agoMaybe I'm missing something here... The big problem with CSS without variables is the time and effort it takes to make changes. If you only have to change the declarations once, at the top of the file, well it doesn't get much easier.
- isleyaardvark 17y agoThere is not only no reason a preprocessor like SASS can't someday efficiently process selectors like he describes, but theoretically it would be easier with something like SASS. In SASS you could keep the color declaration alongside the other CSS declarations, then the preprocessor could simply find all the declarations with that variable and string them together with commas. Unfortunately the SASS preprocessor doesn't do that... yet. The main draw of SASS is the ease of development and maintainability, not reducing the byte size of your CSS files. Personally, I don't want to spend the time manually hunting through CSS to combine selectors in order to save a few bytes. To give you a more practical example, instead of a color like #efac68, imagine the variable held the value 1em or 10px. If you wanted to increase the width of the gutters between columns, it's easier to change $gutter than to try a find and replace of 10px in your CSS, while trying to only change the values you want.
- rradu 17y agoYeah, but if you can have a variable hold more than declarations than just a color value, then that's a lot of space saved.
- deleted 17y ago[deleted]
- gamache 17y agoI can't believe it; a screed against CSS constants, published on April 1st, and it claims not to be a joke.
- kj12345 17y agoIts a good point about comma-delimited selectors reducing repetition, but constants offer other advantages, just as they do in any language. One example is the ability to distinguish in code between !warningColor and !saleColor even if they happen to be the same value of red at a given point in time. Another is increased readability, since scanning a stylesheet and quickly seeing that #f54e4f and #f5e4f4 are very different colors is difficult. Additionally in Jeff's case constants would allow for one complex stylesheet which maps selectors to constants to be shared across all skins, and then each of the 10 skins can be simply definitions of constants.