22

How to select the above element of an element in CSS using selectors

<li class="content">One</li>
<li class="content">Two</li>
<li class="content">Three</li>
<li class="no-content">First</li>
<li class="content">Four</li>
<li class="content">Five</li>
<li class="content">Six</li>

Here I want to use the class no-content, so that I can get its above element <li class="content">Three</li>, using CSS selector.

Temani Afif
  • 211,628
  • 17
  • 234
  • 311
Justin John
  • 8,667
  • 14
  • 67
  • 126
  • Unfortunately I don't think that's possible yet. Same question: http://stackoverflow.com/questions/1817792/css-previous-sibling-selector Edit: If JS is an option it's obviously quite easy: `$('li.no-content').prev().addClass('prev')` – powerbuoy Apr 04 '12 at 06:58
  • 1
    Rather than “above”, the term for the `
  • ` before `
  • ` is “preceding sibling”.
  • – Paul D. Waite Apr 04 '12 at 07:20