DEV Community

Discussion on: CSS: bad parts

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).