Home Is there a CSS parent selector?
Reply: 0

Is there a CSS parent selector?

user9847
1#
user9847 Published in September 19, 2018, 11:03 am

How do I select the <li> element that is a direct parent of the anchor element?

In example my CSS would be something like this:

li < a.active {
    property: value;
}

Obviously there are ways of doing this with JavaScript but I'm hoping that there is some sort of workaround that exists native to CSS Level 2.

The menu that I am trying to style is being spewed out by a CMS so I can't move the active element to the <li> element... (unless I theme the menu creation module which I'd rather not do).

Any ideas?

share|improve this question
  • 25
    I wasn't actually borrowing from the jquery docs I was just trying to illustrate the element that I am trying to select. Your suggestion would select the all of the a children of an li tag (see w3.org/TR/CSS2/selector.html) – jcuenod Jun 18 '09 at 20:41
  • 4
    More discussion of this problem at stackoverflow.com/questions/45004/… – MatrixFrog Jan 20 '11 at 3:55
  • 29
    @Tomas li > a.active selects the child, not the parent. – Stewart Mar 14 '12 at 18:14
  • 1
    Interesting to note that the question @MatrixFrog links to this page under "This question already has an answer" ... – Agi Hammerthief Mar 5 '14 at 14:52
  • 1
    Are there any updates to this question? I believe the last recorded correspondence on the question was in March 2014. Whats going on with it? – Master Yoda Jan 19 '15 at 16:38

27 Answers 27

active oldest votes
up vote 2060 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.483207 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO