Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make !important the whole .class selector

Tags:

css

Is it possible to make the entire .class CSS selector important? I'm thinking in this kind of structure:

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

I don't know if it's possible.

like image 765
mindOf_L Avatar asked Apr 07 '17 08:04

mindOf_L


People also ask

How do you make an entire CSS class important?

important rule in CSS is used to add more importance to a property/value than normal. In fact, if you use the ! important rule, it will override ALL previous styling rules for that specific property on that element!

How do I increase my selector specificity?

As a special case for increasing specificity, you can duplicate weights from the CLASS or ID columns. Duplicating id, class, pseudo-class or attribute selectors within a compound selector will increase specificity when overriding very specific selectors over which you have no control.


1 Answers

No, it's not possible. !important is thought to be an instrument of last resort and as such should be used sparingly. !importanting whole selectors would caricature that idea.

If you need to trump other styles, use CSS specificity to your advantage. You can use, e.g., these techniques to push your style declarations to the top:

  • double class name will trump single class name:

    .custom-selector.custom-selector > .custom-selector

  • ID trumps class:

    #custom-id > .custom-class

  • IDs can be duplicated, too:

    #id#id > #id

  • inline styles trump any stylesheets:

    <style> p#id#id.class.class { color: green; } </style> <p id="id" class="class" style="color:red">I am red!</p> 
like image 179
Boldewyn Avatar answered Sep 24 '22 17:09

Boldewyn