10
That moment I realized I was overriding CSS with !important for everything
I spent six months building a site with fifty !important flags because I didn't understand specificity. Then a senior dev looked at my code and asked why I was fighting the browser instead of using the cascade. What was the one thing that made your coding click?
3 comments
Log in to join the discussion
Log In3 Comments
cameron53814d ago
Man, "fighting the browser instead of using the cascade" really hit home for me. I remember spending a whole weekend slapping !important on everything because I couldn't figure out why my styles weren't sticking, it was such a mess. What finally made it click for me was actually reading through the CSS spec on specificity, like sitting down with a cup of coffee and going through the examples. Once I got that specific selectors beat general ones and inheritance is your friend not your enemy, I ripped out like 40 of those flags and the whole thing just started working smoother. Your mileage may vary, but taking a step back to understand the cascade was honestly the best hour I ever spent on frontend work.
4
spencerm4614d ago
Yeah, those all nighters where you start questioning your life choices because a div won't center properly. I think every web dev has that moment where !important becomes their best friend and then eventually their worst enemy. It's funny how reading the actual rules clears up months of guesswork in an afternoon, but nobody wants to crack open a manual until they're desperate.
1
elizabethg1814d ago
Stop using !important like it's a bandaid and start treating it like what it is, a last resort. I had a site where I used it on about 30 different properties and it took me a whole day to untangle the mess. Once I sat down and wrote out my selectors on paper, I saw how much I was overcomplicating things with classes and IDs stacked on top of each other. Using inline styles for just a few key things and keeping the cascade clean made everything way easier to manage. Now I always check my specificity first before reaching for that hammer.
5