Select the second <p> element within its parent. - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-of-type

Description

Select the second <p> element within its parent.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:nth-of-type(2) {
    background: red;
}
</style><!-- w  w w .j a v a 2s.  c o m-->
</head>
<body>

<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>

<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</div>

</body>
</html>

Related Tutorials