This content originally appeared on CSS-Tricks and was authored by Chris Coyier
If you’re abhorred by using inline styles, just move that style
to the class
attribute! And then make sure you have CSS in place that, ya know, does what it says on the box.
OK lemme dig in and totally ruin the joke.
- First off, it’s a joke, so don’t actually do this. I don’t even mind the occasional inline style for one-off stuff, but this is not that.
- To me the weirdest part is that period (
.
) character. Escaping the more unusual characters with a backslash () feels normal, but what is that period about?
- The little period trick there doesn’t work when the following character is a number (e.g.
.padding:.1rem;
). - You can avoid the escaping and trickery if you go with an attribute selector like
[class*="display: flex;"]
. - This reminds me of Mathias Bynens’ research: CSS character escape sequences. But… that doesn’t seem to work anymore? I wonder if browsers changed or if the tool broke and doesn’t output what it should anymore (e.g. does
.color3a #bada55;
look right?).
Here’s all that playing around:
The post Inline Styles as Classes (lol) appeared first on CSS-Tricks.
You can support CSS-Tricks by being an MVP Supporter.
This content originally appeared on CSS-Tricks and was authored by Chris Coyier
Chris Coyier | Sciencx (2021-06-16T21:11:02+00:00) Inline Styles as Classes (lol). Retrieved from https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.