Re:Tailwind and the Beauty of Ugly Code
by berkle4455 on Friday July 07, 2023 @01:34AM
(#36627616)
is @apply a preprocessor thing? does CSS still not have a native way to do multiple inheritance/traits?
You can use CSS preprocessors such as Sass that have inheritance. But most people doing front end design these days separate out design elements into components, which pretty much completely handles the re-usability of the underlying CSS. But @apply is useful for smaller elements used across components like buttons, form elements, headings, etc.
https://tailwindcss.com/docs/reusing-styles#extracting-class...
I'd also add that the code in the Tailwind example is much easier to maintain and jump in on. It describes everything going on without you having to cross-reference a separate CSS doc with all of the actual meaning hidden in it. Joining a new project with 1000+ line CSS files + media queries randomly added throughout is a horrendous experience.