Inline Styles as Classes (lol)

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.


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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Inline Styles as Classes (lol)." Chris Coyier | Sciencx - Wednesday June 16, 2021, https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/
HARVARD
Chris Coyier | Sciencx Wednesday June 16, 2021 » Inline Styles as Classes (lol)., viewed ,<https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/>
VANCOUVER
Chris Coyier | Sciencx - » Inline Styles as Classes (lol). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/
CHICAGO
" » Inline Styles as Classes (lol)." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/
IEEE
" » Inline Styles as Classes (lol)." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/06/16/inline-styles-as-classes-lol/. [Accessed: ]
rf:citation
» Inline Styles as Classes (lol) | Chris Coyier | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.