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
  • 245,468
  • 26
  • 309
  • 415
Justin John
  • 9,223
  • 14
  • 70
  • 129
  • 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
  • 2
    Rather than “above”, the term for the `
  • ` before `
  • ` is “preceding sibling”.
  • – Paul D. Waite Apr 04 '12 at 07:20