Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Parent/Ancestor Selector [duplicate]

Possible Duplicate:
Is there a CSS parent selector?

I know this is a shot in the dark, but is there a way, using css only, CSS2, no jquery, no javascript, to select and style an element's ancestor? I've gone through the selectors but am posting this in case I missed something or there is a clever workaround.

For example, say I have a table with classname "test" nested inside a div. Is there some sort of:

<div>
    <table class="test">
    </table>
</div>
div (with child) .test
{
     /*styling, for div, not .test ...*/
}
like image 585
Steve Avatar asked Aug 09 '09 17:08

Steve


People also ask

How do you target a parent element in CSS?

The element>element selector is used to select elements with a specific parent. Note: Elements that are not directly a child of the specified parent, are not selected.

Is there a CSS parent selector?

Let's be clear here, just in case someone is finding this from a search engine: there are no parent selectors in CSS, not even in CSS3.

How do I target a sibling in CSS?

Adjacent Sibling Selector (+) The adjacent sibling selector is used to select an element that is directly after another specific element. Sibling elements must have the same parent element, and "adjacent" means "immediately following".

How do I find my ancestor in CSS?

The first selector is the "ancestor", the element(s) that must be located higher in the tree, and the second selector is the "descendant", the element(s) that must be located somewhere underneath the ancestor in the tree. To understand ancestor/descendant relationships, you need to think about the webpage is a tree.


1 Answers

There is no such thing as parent selector in CSS2 or CSS3. And there may never be, actually, because the whole "Cascading" part of CSS is not going to be pretty to deal with once you start doing parent selectors.

That's what jQuery is for :-)

like image 192
ChssPly76 Avatar answered Sep 17 '22 16:09

ChssPly76