CSS :first-child pseudo-class simple example not working
As far as I can tell, this simple example below should be working but it doesn’t. I’m obviously missing something, but I can’t for the life of me figure it out.
.field div should have red text, but it simply does not…
Running Chrome browser on Mac.
The HTML is invalid.
p element can’t contain a
div element. This results in the following:
As you can see, the browser is automatically closing the
p tags, which explains why your selector isn’t matching anything.
If the HTML was actually valid, then your selector would work. For instance, if you replace the
div elements with
span elements, the following would work: