Reputation: 63
i need ur help i want to translate from XPath to css i have this code and this xpath:
/descendant::p/parent::*/child::p[position()=1]
... Selected will be (B D F H )
<?xml version="1.0" ?>
<book>
<title>A</title>
<p>B</p>
<p>C</p>
<chapter>
<p>D</p>
<p>E</p>
<section>
<p>F</p>
<section>
<title>G</title>
<p>H</p>
</section>
<p>I</p>
</section>
</chapter>
HOW i can translate this to CSS?
Upvotes: 1
Views: 118
Reputation: 4014
Try this:
p:first-of-type {
/** Your style here **/
color: red;
}
Supports all major browsers and IE9+
Upvotes: 2
Reputation: 99484
I'm not sure about what you're exactly looking for, but using p:first-of-type
selects the first paragraph elements inside their parent:
p:first-of-type {
background-color: gold;
}
Selected elements: B D F H
: Demo.
Upvotes: 3