-1

i have this unordered list

<ul>
     <li> test1</li>
     <li>test2 </li>
     <li class="current">test3</li>
     <li>test4</li>
</ul>

what i want to do is to select the .current child and access the test2 from it. That means to select .current and go back one step back to test2

Same for test1 go back two steps to get test1 and associate different CSS to it.

Is it feasible ?

Ahmad Alfy
  • 13,107
  • 6
  • 65
  • 99
Roh-Land
  • 481
  • 1
  • 4
  • 4

2 Answers2

5

There is no previous sibling selector or parent selector, so no, it is not feasible with pure CSS.

If you used some javascript it would be quite easy, something like

document.getElementsByClassName('current')[0].previousSibling.style = /* Whatever you want here */;

Assuming that there is only one current class at a time

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
0

In future browsers CSS Level 4 Selectors will enable you to solve this problem more easily using something like the following (WIP) :

!li + .current {}

See: http://dev.w3.org/csswg/selectors4/#subject

M.S.
  • 442
  • 3
  • 13