Xlist aref vs nth4/17/2023 ![]() But what if we want to select odd or even elements instead? Perhaps we’d like to pick the sixth element in a document subtree, or apply styles to every third element. The ability to select the first and last children of a document is fine. Change :first-child to li:first-child and :last-child to li:last-child. If we qualify :first-child and :last-child by adding a simple selector, it all makes more sense. We’ve essentially typed *:first-child and *:last-child. But why are the remaining li elements green? Well, that’s because :last-child is also unqualified, and ul is the last child of body. After all, h2 is the first child of body, and li is the first child of the ul element. You can see what this looks like in the figure below.īecause :first-child is unqualified, both the h2 element and first li element are hot pink. Let’s take a look at the HTML and CSS below: As with other pseudo-classes, :first-child and :last-child have the fewest side effects when qualified by a simple selector.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |