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
  • 32,451
  • 45
  • 138
  • 193

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 Jenkins
  • 51,445
  • 11
  • 72
  • 100
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
  • 30,599
  • 2
  • 28
  • 29