Complex CSS selector for parent of active child [duplicate]

According to Wikipedia:

Selectors are unable to ascend

CSS offers no way to select a parent or ancestor of element that satisfies certain criteria. A more advanced selector scheme (such as XPath) would enable more sophisticated stylesheets. However, the major reasons for the CSS Working Group rejecting proposals for parent selectors are related to browser performance and incremental rendering issues.

And for anyone searching SO in future, this might also be referred to as an ancestor selector.

Update:

The Selectors Level 4 Spec allows you to select which part of the select is the subject:

The subject of the selector can be explicitly identified by prepending
a dollar sign ($) to one of the compound selectors in a selector.
Although the element structure that the selector represents is the
same with or without the dollar sign, indicating the subject in this
way can change which compound selector represents the subject in that
structure.

Example 1:

For example, the following selector represents a list item LI unique child of
an ordered list OL:

OL > LI:only-child

However the following one represents an ordered list OL having a unique child,
that child being a LI:

$OL > LI:only-child

The structures represented by these two selectors are the same,
but the subjects of the selectors are not.

Although this isn’t available (currently, November 2011) in any browser or as a selector in jQuery.

Leave a Comment