0

I just writing a userscript, for override the page native style.


I have a part of CSS:

foo#bar {
    background-color: black !important;
    color: red !important;
    font-size: 14px !important;
    font-weight: bold !important;
    position: absolute !important;
    top: 20px !important;
    right: 200px !important;
    z-index: 999 !important;
}

can I mark whole group with !important? Like this:

foo#bar !important {
    background-color: black;
    color: red;
    font-size: 14px;
    font-weight: bold;
    position: absolute;
    top: 20px;
    right: 200px;
    z-index: 999;
}

(It just a demo, I know that is not work.)


Non-English native speakers, so sorry.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
LianSheng
  • 448
  • 5
  • 17
  • first NO! second learn about `!important` :https://css-tricks.com/when-using-important-is-the-right-choice/ – לבני מלכה Feb 03 '19 at 06:46
  • Try to avoid !important as much as possible. There is almost always a better way to do it. If you are having a specific case where your styles are not displaying correctly, post another question about it here on SO. You should be able to get an answer that will be much better than using !important. Do you know why your styles are not working in the first place? – kojow7 Feb 03 '19 at 06:54
  • Why would you??? declaring style for ID does that for you. If you are worried about styling getting stepped on and you cant do inline (I hate inline) then make sure your stylesheet steps on others – yardpenalty.com Feb 03 '19 at 07:04

1 Answers1

1

No, it is not possible to do this with CSS.

Also, you should not be using !important on this many properties - if you think you need to do this, it is a symptom of some other problem with your architecture. Usage of !important is reserved for rare cases where you need to override a CSS property without using the cascading aspect of CSS, such as if you're not able to create a selector with equal or greater specificity. Again, these cases are extremely rare.

Our_Benefactors
  • 3,220
  • 3
  • 21
  • 27