DEV Community

Discussion on: Common Frontend Interview Questions I've Been Asked

Collapse
 
gibbitz profile image
Paul Fox

Generally if I ask

4.What does important mean in CSS styling?

it's to ferret out bad practices. Using !important in your CSS makes fixing issues through the cascade more difficult and is the reason that overusing descendant selectors is frowned upon (often using !important is brought on by specificity wars in your CSS). Recognizing that you're reaching for this to fix an issue should be a red flag to you and showing that you recognize it as an anti-pattern would get you a pass on my interviews.

Collapse
 
alohci profile image
Nicholas Stimpson • Edited

It wouldn't on mine, and I'd take a dim view of such an opinionated approach to a 25 year old integral feature of the cascade. I'd much prefer to hear an explanation of how it can be used positively in conjunction with specificity and ideally, cascade layers.

Which, of course, is quite a problem if different interviewers can seek almost diametrically opposing answers to the same question.

Collapse
 
fen1499 profile image
Fen

I believe the composition of both goods and bads would form an even better answer, but what would be a correct answer about it's positive usage? I only used it a few times as a fast fix for some CSS mess that someone previous maintainer made.

Thread Thread
 
gibbitz profile image
Paul Fox

You hit the only good point. Speed. Even in it's implementation !important feels like a hack. It is the only property specification that affects the cascade and at that it short circuits it. If you have a production issue you need to patch in code you don't maintain, this would be a temporary fix.