Furnish JavaScript - Let the classes on DOM elements generate the CSS for you
github.com
github.com
It cannot be as powerful as just using css. It may even require mixing the two together. It doesn't make sense because these aren't what classes are for. If I have an "item box" I want the markup to reflect that by assigning it the class named "item-box."
Sometimes you really do come across an alternate language that is better in little ways and equally expressive.
<p class="fs14px mt25 mb0 ml2em br30%">You can combine formulas as well</p>
vs <p style="font-size:14px; margin-top:25px; margin-bottom:0; margin-left:2em; border-radius:30%;">inline css</p>It's JavaScript to accomplish what the browser will already do for you with little savings in typing. A plain-vanilla CSS file would be less work!
It's hard to read the industry when people are throwing out thorough progressive enhancement in favor of thick client SPAs, when not too long ago people praised development practices that ensured JavaScript was not a necessity for experiencing the web.
I feel like we nearly had everything perfect, but then new frameworks and tooling came around and challenged these things. We're in a better place now I think, but we've left behind some great development practices, too.
Might be interesting to run this in Node and have it actually output a CSS sheet of all the selectors you use -- a sort of compilation step to build a sheet of just the stuff you need and to take advantage of the performance benefits of plain-old-CSS.
A few ideas for where to take it come to mind:
Ditch the JS and just write a library of generic CSS classes that solve common use cases. Crucially these have to provide at least _some_ abstraction above raw CSS styles (e.g. "always-centered-vertically" and not "margin-left"). There are lots of these libraries out there already, but maybe there is room for something a little less opinionated, or lower level, or higher level, or whatever than what you get with, say, Bootstrap.
Keep JavaScript in the mix but use it at build time, not in the browser. Maybe you scan the source to see which classes are actually used and dynamically generate a .css file to send to the client that only includes those classes and no others. Or maybe you could use JS to do some fancier layout solving - depending on the structure of the dom elements in the source - to generate correct CSS attributes to support the abstraction.
I'm not super familiar with the state of CSS tools, so maybe things like what I'm describing already exist by the dozens. I just know that CSS is a pain, and I appreciate anyone who wants to make working with it easier.
I guess if you only make HTML email templates, this is the library for you!
No JS in html emails, it doesn't work at all.
Not sure how well this is going to work with the CSS being applied by JS after the render; I suspect it would tend to suffer from FOUCs. It would be nice to see an example implementation to allay those concerns. I do like the basic pattern though, as long as it's used sparingly. I find it more convenient to add classes like these than to use inline styling, even if there's no operational advantage, as these format classes are often applied in addition to other classes.
Creating a class called margin-b10 is tantamount to the following C code:
int one = 1, two = 2, three = 3;
And then using 'one', 'two', and 'three' instead of 1, 2, 3.If you're naming your classes to create abstractions, i.e. 'article-box' or 'navbar-section' then it makes a lot more sense.
[1] http://acss.io
* ...does the page look before the JavaScript loads
* ...do you handle media queries, pseudo selectors, pseudo elements
* ...is this better than inline styles (only one I can think of immediately is support for stuff like autoprefixer, but that isn't needed for any of the provided functionality)
Basically, what's the benefit here? Is is just to avoid using inline styles? Has the anti-inline-style dogma become so strong that we basically invent a version of inline styles just to get around using them?
Oh god now I'm having flashbacks to <tr align="center"><td colspan="3" nowrap><img src="spacer.gif" height="100" width="150"></td></tr> make it stop.
However I doubt it would good enough that I wouldn't hate it and refuse to use it.