DEV Community

Discussion on: CSS: bad parts

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

Hey stereobooster, I've got the impression that a lot of "old school" developers really like global styles. They praise the cascading feature of css, which helps them keeping their code "dry". I think that's one of the reasons why many of them hate component based spa frameworks/libraries - they're "forced" (or advised) to split their css, too. Unfortunately I struggle to convince them that decoupled components are of much greater benefit than "dry" css.

What's your opinion? Can you give me some more arguments for my discussions?

Collapse
 
giorgosk profile image
Giorgos Kontopoulos 👀 • Edited

I don't consider global code (classes) bad on their own sometimes it is needed. I think they are called utility classes with some of the css frameworks. And yes dry is one of the reasons to use it but another one is consistency. For example you want a certain animation done when hovering over a link on LOTS of parts of your site/app can be different components in modern web apps. Without a reusable utility class you are recreating the same exact code (perhaps with copy/paste) and might run into inconsitencies if you have to modify this behaviour later on but you are also bloating the final .css with the same code multiple times.

In that sense those classes are global and not part of any component and any component can choose to use them when needed.

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

Oh, I din't mean shared/global code in general, Giorgos. I only had global CSS code without namespaced classes in mind (...where you can shoot yourself in the foot with cascading selectors).

Collapse
 
stereobooster profile image
stereobooster

It's a really big topic here (and to be fair, not what I aimed in this article). I will be not the first and the most significant author to talk on the subject. Maybe check those talks: