-1

Is there a more compact way of writing this for example?

.behind a.delete-btn, 
.behind a.delete-btn:active, 
.behind a.delete-btn:visited, 
.behind a.delete-btn:focus, 
.behind a.delete-btn:hover {
    color: white;
    background-color: red;
    text-shadow: none;
}
ksloan
  • 1,482
  • 1
  • 13
  • 19

1 Answers1

2

Currently there isn't a shortcut syntax for this.

Selectors 4 will provide a :matches() pseudo-class that essentially provides this shortcut syntax, but the only implementations exist as prefixed :any(), which are reserved for internal use and testing purposes. Plus, due to parsing rules, trying to use :any() in its prefixed state would require repeating everything anyway, so you're better off waiting until browsers start implementing the standardized :matches().

Meanwhile, if you're trying to override existing styles on a elements for all states, and .behind a.delete-btn by itself is not specific enough, you can cheat by doubling one of the classes (since a class selector and a pseudo-class have the same specificity):

.behind a.delete-btn.delete-btn {
    color: white;
    background-color: red;
    text-shadow: none;
}

If this is too hacky for you, then there's no other way than to specify all its state pseudo-classes again as you have done.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356