Solve the problem of first-child and last-child not valid

Problem description: Using structural pseudo-classes first-child and last-child will sometimes fail.
Reason: The effective condition of the selector is actually that the last child element of div must be p, but in the actual HTML structure, various types of elements are always interspersed. Together, the
solution: use div p:last-of-type, only find from p elements, and ignore other types of elements.
p:last-of-type {background-color: blue;}

Guess you like

Origin blog.csdn.net/vigorZ/article/details/107949291