i am curious to know how the nth-child css selector works. I was expecting the following code to change the background color for the 3rd
element, that is "The third paragraph". However, when I run this code, the 2nd
element is getting selected and "The second paragraph" has a changed background color.
<html>
<head>
<style>
p:nth-child(3) {
background: #ff0000;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</body>
</html>