当前位置: 首页 > Web前端 > CSS

cssselectorlast-child&last-of-type

时间:2023-03-30 16:00:11 CSS

last-child[同first-child]:last-child表示其父元素的最后一个子元素,该元素为css指定的元素生效。last-of-type[同first-of-type]:last-of-type表示其父元素最后指定的元素类型。这两者的区别在于last-child必须多一个条件,即必须是parent元素的lastchild元素强调最后一个child,而last-of-type只需要匹配最后一个类型即可.【例12】缺点:对元素选择伪类比较准确,但是类选择器选择伪类可能不准确【例34】现在看例子:1、一般情况下,以下所有ul无干扰元素都是lihtmlcss结果:都将在最后一个li生效。last-childlast-of-type2、ul下不仅有li,还有其他元素。这也是实际场景中会出现的htmlcss结果:last-child不能选择目标元素,last-of-type可以选择目标元素last-childlast-of-type3.选择某某的最后一项typehtmlcss][11]结果:last-child和last-of-type都不会选择某个type的最后一项。line:last-child和.line:last-of-type4.选择最后一个类名htmlcss父元素下同名和异名元素的result:last-child被选为最后一个子元素和最后一个类名元素;last-of-type会选择不同元素的最后一个child.line:last-child.line:last-of-type