3

Can I use CSS to select a parent of an element without using jQuery or JavaScript (pure CSS).

Here is my code

<nav>
    <ul class='page-numbers'>
        <li><span class='page-numbers current'>1</span></li>
        <li><a class='page-numbers' href=/page/2/'>2</a></li>
        <li><a class='page-numbers' href=/page/3/'>3</a></li>
        <li><a class="next page-numbers" href="/page/2/">Next Page</a></li>
    </ul>
</nav>

Please note that there is a class called current, and in the example above, it is on the first page. This current class will be inserted into any page that is the current page (so if the current page is the second page, the second item in the list will have the current class.

Now using CSS only (without jQuery or JavaScript), how can I select the list element that has a child with the class current?

Please do not suggest changing the HTML because it should be the way it is because this is the requirement.

Greeso
  • 5,502
  • 6
  • 43
  • 65

2 Answers2

1

You basically cannot do it just with CSS, you will have to use javascript, as can be seen in this this old question with a lot of votes: Is there a CSS parent selector?. (checked that the answer is about CSS 3 as well as CSS 2).

Community
  • 1
  • 1
Francisco Presencia
  • 8,240
  • 6
  • 40
  • 83
-1

Did you have a look at the url http://css-tricks.com/parent-selectors-in-css/