解决first-child、last-child 不生效问题

问题描述:用结构伪类first-child、last-child有时会失效
原因:选择器的生效条件其实是div最后一个子元素必须是p,但实际HTML结构中,总会各种类型元素夹杂穿插在一起
解决方法:使用div p:last-of-type,只会从p元素中找,会忽略其他类型元素,
p:last-of-type {background-color: blue;}

猜你喜欢

转载自blog.csdn.net/vigorZ/article/details/107949291