CSS3 Selector: select a parent node of a specific node?

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!


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.

链接地址: http://www.djcxy.com/p/22834.html

上一篇: 基于子选择器的CSS样式父项

下一篇: CSS3选择器:选择特定节点的父节点?