1

Is there a way to write a rule set equivalent to the following while only using one .active selector?

.active #pselect,
.active #bselect,
.active #cselect,
.active #nselect,
.active #iselect {
    color: white;
}
Sean
  • 6,873
  • 4
  • 21
  • 46
  • 1
    it looks like you really need to add a class to all of your active elements and select for that class – Culyx Mar 28 '18 at 16:05
  • 1
    use a class instead after-all, that's what they're for. Also it stops you from getting into specificity nightmares – Pete Mar 28 '18 at 16:06
  • You would use a class instead of ids to apply the `color: $white` Maybe add your html so we can better see what's going on. a [mcve] always helps. – admcfajn Mar 28 '18 at 16:06
  • Possible duplicate of [Is there a CSS selector by class prefix?](https://stackoverflow.com/questions/3338680/is-there-a-css-selector-by-class-prefix) – TylerH Mar 28 '18 at 17:41
  • @TylerH Even though the answers are similar, this is a distinctly different problem than the question you referenced. – Sean Mar 28 '18 at 18:38

1 Answers1

7

Ideally you would add a class to the elements you're selecting by id. But if that's not possible, you could use an attribute selector:

.active [id$="select"] {
  color: white;
}

This particular attribute selector selects all elements with an id value that ends with "select".

Sean
  • 6,873
  • 4
  • 21
  • 46