DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

Tell me about the worst CSS you've ever had to deal with

Story time!

Latest comments (41)

Collapse
 
ksp_music_lover profile image
Pradeep KS

For me, It was float:left or right whatever. But big relief when started using flex and grid.

Collapse
 
facundocorradini profile image
Facundo Corradini • Edited

Beating inline !important

This is gonna be awful, so brace yourselves...

Had to work with HTML generated by closed-source, god-knows-what-language, third-party legacy script that had inline !important declarations. I kid you not.
It seems that dev really, really didn't wanted anyone to adapt their style. Any request to change that would fall into the "we don't know how to do that, the original dev is long gone and nowhere to be found" category.

I was tasked with changing those styles to better suit the website. "impossible" was my first thought, both internal !important and external !important would fall short to change such an absurd priority. Then I remembered the only way to beat internal !important: animations.

So the first step in fixing this mess was to create instant animations that used keyframes to beat the priority.

But it wouldn't be so "simple", oh no. The code didn't had classes or a structure I could easily target with element selectors, so I had to use attribute selectors targeting the style attribute that matched the properties.

Something the likes of

<!-- HTML with inline, important styles setting blue font -->
<p style="color:blue !important">test</p>
/* external CSS, the only thing I was allowed to change */
[style*="color: blue"] {
  animation: change-color 0.1ms forwards;
}

@keyframes change-color {
  to {
    color: red;
  }
}

And it worked. The final output of that code will be red text, beating the inline !important declaration that tries to set it to blue.

Of course the real case was much more complicated than that example, as there was lots of conflicting stuff that made the hack quite complex and fragile. Not fun. At all.

But at the end of the day I got the thing working, feeling extremely proud. And extremely ashamed.

Collapse
 
jwesorick profile image
Jake Wesorick

Anything dealing with emails.

Collapse
 
arximughal profile image
Muhammad Arslan Aslam

One of the worst CSS I usually have to deal with every once in a while looks something like this:

html { background-color: #e0e0e0; }
body { color: rgba(0, 0, 0, 0.87); font-size: 0.875rem; background-color: #f0f0f0; -webkit-font-smoothing: antialiased; }
*:focus { outline: 0 !important; }
a { color: inherit; text-decoration: none; cursor: pointer; outline: 0; }
a:hover, a:focus { color: inherit; text-decoration: none; }
button { color: inherit; }
pre { color: inherit; background-color: #f8f8f8; border-color: rgba(120, 130, 140, 0.13); }
blockquote { border-color: rgba(120, 130, 140, 0.13); }
small { font-size: 90%; }
sup { position: relative; top: -1em; font-size: 75%; }
.pull-center { position: absolute; left: 50%; }
.close { font-size: 1.3rem; }
.img-responsive { width: 100%; height: auto; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.pull-left { float: left; }
.pull-right { float: right; }
.center-block { margin: 0 auto; }
.avatar-profile{ width:100% !important}
.heading-settings{ border-bottom:2px solid #ccc; overflow:hidden; clear:both}
.edit-button a{ margin-top: 20px; margin-right:20px;}
.heading-settings h3{ margin:0;}

One of my colleagues thinks it's best to write "COMPRESSED" CSS from start instead of compressing it later on.

Collapse
 
prafulla-codes profile image
Prafulla Raichurkar • Edited

Aligning elements using float:left and right and also using tags like center which i much later found out that those tags were deprecated

Collapse
 
dana94 profile image
Dana Ottaviani

CSS files where the same classes were overwritten multiple times. 😅

Collapse
 
zakwillis profile image
zakwillis

Going to make a point here which escapes most people. It kind of goes back to xslt, and in some ways links to svelte, react etc. If you can drive most code from meta data, it doesn't really matter if the css, or js is bad (of course it does, but...). The real issue is when managers and product managers won't let the developer do the right thing. There may be good reason why they won't.
I tend to look at most development as something which should/could be templated in the future unless it is domain specific. The question is whether we should go that extra mile.
Employ a css expert, Sql guru, python extroadinairre, but if they are still doing expertise two years in, something is l wrong.
This is why I am not a fan of code bashing/honour shaming.

Collapse
 
phizzard profile image
Phil Tietjen

I'm not sure if this is the worst I've dealt with but it's up there and is first on the mind.

At a previous job, I was leading the development of an e-commerce website (I really shouldn't have been but that's a different story, but it does add to the CSS issue) so we had a regular contractor to focus on the designs and styling of our pages as they were specialized.

We were using bootstrap 4, which they were actually quite happy we were. For a while throughout the development, I noticed a lot of pages weren't responsive; which was quite surprising considering bootstrap's rows and columns can do a lot of the heavy lifting towards responsive layouts, but it was known that they were "working on it".

Days before launch some of the major pages still weren't responsive which was making me tense, so I decided to take a look and I had found that they had created their very own column classes using CSS Grid that didn't account for different screen sizes!

I wish I still had the CSS to show snippets off, but the worst part about this CSS to me was just making worse copies of classes already given to us by a framework.

Collapse
 
molly profile image
Molly Struve (she/her)

All CSS scares me! 😂

Collapse
 
melissamcewen profile image
Melissa McEwen

CSS I couldn't find in a Drupal site I inherited. It was inline and I just couldn't figure out where it was coming from. Searching the code base was futile. Finally I found it in a Views (a Drupal content display tool) configuration buried under a setting I'd never even seen used before.