Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Selector: select a parent node of a specific node? [duplicate]

Possible Duplicate:
Is there a CSS parent selector?

Hi!

I'm trying to select a parent node of a specific node (with a specific className) to apply some CSS style to it.

As far as I know, there only exist CSS3 selector operands for child elements, descendant, following nodes etc... So only some "forward" selection in the DOM document is possible. When the selector applies to some section in the DOM document, always the last element the selector describes, is being selected. Am I wrong? I hope so!

How do you select the first <div> element in the following example? Let's say that there may exist a lot of other <div>s containing <p>s and I only want to select the <div>s containing a p.foo but not p.bar. Note that I want to select the <div> rather than the <p>!

<div>
    <h1>Test</h1>
    <p class="foo">Some text</p>
</div>
<div>
    <h1>Test 2</h1>
    <p class="bar">Some other text</p>
</div>

Thanks in advance!

like image 228
leemes Avatar asked Sep 02 '25 05:09

leemes


1 Answers

Indeed a "parent selector" doesn't exist.
You can see the list of selectors here: http://www.w3.org/TR/css3-selectors/#selectors

You could give your parent node an id and then select the parent with its id.
Otherwise I don't see any solution to access the div from bottom up using solely CSS.

like image 80
brillout Avatar answered Sep 04 '25 20:09

brillout