I've been hearing more and more about the concept of applying inline styles through JavaScript as opposed to using CSS. There's been an article floating around regarding the idea, too (https://css-tricks.com/the-debate-around-do-we-even-need-css-anymore/). What's your take?
As someone who writes CSS frameworks for a living, I don't know if I could ever give up the powerful globalness of the "c" (cascading.) Though, I do find myself writing more and more inline styles for elements that are specific to a block or page to avoid bloating the framework. I'm thinking a blended approach is in my future.
I think he is glossing over CSS main selling point which is a separation of concerns. Essentially, you can code a web-site unstyled and then let an independent 3rd party write a style sheet for it.<p>He is saying that you would have a 'style.js' performing the task, but he is not specifying exactly how that file would replace the 'style.css'. A designer writing the 'style.js' key-value pair seems implausible as does converting a designer-created 'style.css' to 'style.js'.
Random thoughts: As far as I understand it, CSS is declarative. JavaScript, not so much. The declarative aspect of CSS is nice; you just specify what you want and CSS handles everything else for you.<p>I am also idly wondering how this would all work out in "HTML and CSS as s-expressions" à la Ŝablono <a href="https://github.com/r0man/sablono" rel="nofollow">https://github.com/r0man/sablono</a>
To me this is a bit of a 'baby with the bathwater' scenario. CSS has problems (particularly lack of namespacing), but I don't think the solution is to just pack up shop on stylesheets and port everything to js. If the argument is about logic, then postCSS and manipulating the CSSOM are cleaner approaches IMO. And with web components the modularity concern is pretty much entirely mitigated. There's definitely an argument to be made about javascript's role styling, but I think it should be complimentary alongside the purely declarative stylesheet.
Personally, I think there is a lot of magic yet to be discovered in dynamically manipulating the CSSOM (CSS Object Model).<p>Case study: If trying to manipulate some ~100 inline-block elements into a grid, with dynamic (say, zoomable + pannable + screen size dependant) width, height and offset. It makes way more sense to programmatically modify the stylesheet using the CSSOM API with fast calculated values, rather than applying unique styles to each of those 100 elements in the DOM, O(1) vs O(n) - yes?
Ironically enough, Netscape proposed a JavaScript Style Sheets specification back in 1996 to replace CSS, but was rejected for being too complicated: <a href="https://en.wikipedia.org/wiki/JavaScript_Style_Sheets" rel="nofollow">https://en.wikipedia.org/wiki/JavaScript_Style_Sheets</a>