2

I have an element with a ng-list attribute. The very next sibling to this element is an <ol>. I want to write a CSS selector that selects this <ol>.

In other words, I want to write CSS that applies to an <ol> when the <ol> has an immediate previous sibling of [ng-list].

Possible?

core
  • 31,265
  • 43
  • 134
  • 192

2 Answers2

4

It's called an adjacent sibling selector.

For starters, I would never ever write this CSS selector, you're tying to an angular attribute, it makes no sense. You should just give you OL a class.

[ng-list] + ol { /* rules here */ }
Adam
  • 46,658
  • 11
  • 63
  • 84
2

CSS doesn't have a 'previous element' selector yet.

Since you want to select the ol that immediately follows another element, use +, it will select only the specified element that immediately follows the former specified element.

In your case

[ng-list] + ol {
    /* css rules */
}

Ref: 5.7 Adjacent sibling selectors

Arbel
  • 29,356
  • 2
  • 26
  • 29