To do! The whole .class selector is important

Is it possible to make the whole CSS.class selector important? I think in this structure:

.custom-selector !important { display: inline-block; vertical-align: middle; position: relative; padding-left: 5px; } 

I do not know if this is possible.

+5
source share
2 answers

No, It is Immpossible. !important is considered a tool of last resort and as such should be used sparingly. !important whole selectors will caricature this idea.

+7
source

First of all, itโ€™s important to apply one specific declaration in the CSS rule. This does not apply to the class. So no, you cannot make a class! Important.

Secondly, only one piece of CSS specificity is important. You can also use other ways to make the rule a more specific rule in order to take precedence (for example, refer to the identifier in the parent chain, and not just the class. When I write CSS, using! Important is my last possible choice - I would rather decide to override other solutions are specific. Usually, if you control all CSS, itโ€™s pretty easy to avoid using it! Important: If you need to override some CSS that you donโ€™t control, sometimes itโ€™s convenient.

Check out this question here for more details. How it explains things better.

+1
source

Source: https://habr.com/ru/post/1266459/


All Articles