0

in code below i try to make last child of p elements color to red but don't work, but first child by :first-child pseudo element work. in this case last child of div element would be to color red, but last child of body wouldn't.

`

p:last-child {
  color: red;
}
<body>
    <p>Lorem, ipsum.</p>
    <p>Lorem, ipsum.</p>
    <p>Lorem, ipsum.</p>
    <div>
      <p>Lorem, ipsum.</p>
      <p>Lorem, ipsum.</p>
      <p>Lorem, ipsum.</p>
    </div>
    <p>Lorem, ipsum.</p>
    <p>Lorem, ipsum.</p>
    <p>Lorem, ipsum.</p>
  </body>

`

  • 1
    Have a look into the DOM inspector. The last paragraph is in fact not the last child of the body. – JSON Derulo Oct 05 '22 at 07:57
  • _"but last child of body wouldn't"_ - that's because the last child, at least in this snippet here, is not a `p`. You can easily see that, when you inspect the whole thing using your browser's DOM inspector. – CBroe Oct 05 '22 at 07:58

0 Answers0