0

Can we use the ampersand operator instead of important?

Below is my sample CSS. Is there any way to use the && operator instead of using !important to override the basic CSS?

Sample snippet

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue !important;
  }
}

Can we replace it with ampersand operator like below in CSS?

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue &&;
  }
}

or it is just !important in css to $i

Amir Shabani
  • 3,857
  • 6
  • 30
  • 67
Learner
  • 8,379
  • 7
  • 44
  • 82

1 Answers1

2

I've never seen the double ampersand before and can't find it in any documentation, I'd like to know where you found it (perhaps less or sass?). It is not a replacement for !important, at least not in any of my browsers which are all quite up to date.

As for !important, it is a way to override css, but it's generally not advised. General advice is, if there's some other css which you'd like to override, see how specific it is and try to be even more specific. That way you prove you really mean it articulately, rather than being forceful.

See this answer for detail on the "controversial" use of !important: What are the implications of using "!important" in CSS?

Seph Reed
  • 8,797
  • 11
  • 60
  • 125