by lf-non · 10y ago · 0 comments
We have pushed CSS pre-processors to the extent that they now have variables, loops, modules, interpolation, conditions etc. which have always been present in javascript.
It makes a lot more sense to just fully embrace all these features from standard javascript instead of building entire ecosystems of css pre-processors with superficial syntactical differences.
It's ironic that graphic tool kits for desktop or mobile apps are adopting CSS and declarative approach, when the front-end is desperately pushing for javascript everywhere.
That said, the main advantage for writing CSS in JS is being able to rewrite styles in runtime, where changing values in Javascript automatically reflects in style changes. The most direct way to do this today is setting variables as data-attributes in a DOM node and targeting specific true/false values for that attribute in your stylesheet.
Native CSS Variables will make life much easier in this respect, but it will still take a couple of years before all major browsers implement it.