1

I want to make it so my rules apply by default to all the sites/pages except the ones I list.

Sort of like an opposite of @document domain(mozilla.org)

https://developer.mozilla.org/en-US/docs/CSS/@document

edit:follow-up regex

Community
  • 1
  • 1
laggingreflex
  • 32,948
  • 35
  • 141
  • 196

2 Answers2

1

There isn't an easy way to do this currently, as noted in this CSS Conditional Rules draft with a link to a Mozilla bug report:

This syntax doesn't offer any ability to do negations, which has been requested in Mozilla bug 349813. Use cases that people have wanted negations for include:

  • User style sheets that want a particular rule in general, but know that that rule does more harm than good on specific sites.

  • Authors who have a rule that they want to apply to most of their pages, but wish to make a few exceptions for.

Hopefully, they'll propose and implement such a feature soon.

In the meantime, you may be able to achieve something with regexp() which accepts a JavaScript regex with certain flags — details are included in the spec — but I can't make any guarantees.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
1
@document regexp('.+mydomain\\.com\/(?!nope|nah).+') {
    .someClass{}
}

This will match mydomain.com while excluding mydomain.com/nope and mydomain.com/nah

In your case regexp('https?://(?!domain1|domain2|domain3).+') perhaps.


https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document

Note that regular expression must match the entire URL, not just a part of it.

For example, this rule:

@document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") { body { font-size: 20px ! important } }

changes the font size of the body element for pages such as http://www.w3.org/TR/2011/PR-CSS2-20110412/.

Note that the backslashes in the regular expression require CSS escaping as \\.


https://developer.mozilla.org/en-US/docs/Web/CSS/@document

Initially in CSS Conditional Rules Module Level 3, @document has been postponed to Level 4.

guvusaza
  • 11
  • 1