css中30个最常用的选择器(4)
点击次数:更新时间:2011-08-10 11:08:06【打印】【关闭】
26. X:first-child :first-child伪类用于匹配一个序列的第一个元素。我们经常用它来实现一个序列的第一个元素或最后一个元素的上(下)边框,如: ul:nth-last-of-type(3) { 兼容浏览器:IE7+、Firefox、Chrome、Safari、Opera 27. X:last-child
兼容浏览器:IE9+、Firefox、Chrome、Safari、Opera 28. X:only-child
<div> 兼容浏览器:IE9+、Firefox、Chrome、Safari、Opera 29. X:only-of-type li:only-of-type { 这个伪类匹配的是,在它上级容器下只有它一个子元素,它没有邻居元素。例如上面代码匹配仅有一个列表项的列表元素。 兼容浏览器:IE9+、Firefox、Chrome、Safari、Opera 30. X:first-of-type :first-of-type伪类与:nth-of-type(1)效果相同,匹配出现的第一个元素。我们来看个例子: <div> 在上面的html代码中,如果我们希望仅匹配List Item 2列表项该如何做呢: 方案一: ul:first-of-type > li:nth-child(2) { 方案二: p + ul li:last-child { 方案三: ul:first-of-type li:nth-last-child(1) { 兼容浏览器:IE9+、Firefox、Chrome、Safari、Opera。 |