hover在前面已经介绍过,IE6下只支持a的hover。
这里提到一个很有意思的东西,即使用border-bottom: 1px solid black; 要好于text-decoration: underline;从实际的效果来看,使用border-bottom的距离比text-decoration来的合理,但使用border-bottom存在一些风险,比如颜色问题。
20.X:not(selector)
div:not(#container) {color: blue;}
否定伪类选择器,这还是比较好理解的,上述将会把非id为container的div的字体颜色设置为蓝色。
:not伪类IE8并不支持,IE9已经支持了。
21.X::pseudoElement
p::first-line {font-weight: bold; font-size: 1.2em;}
::伪类,用于给元素的片段添加样式,这如何理解呢?比如你要让一个段落的第一行的文字加粗,那么这个选择器是不二之选。
除此之外,你还可以给第一个字加上特殊样式,这个应用还是非常常见的
p::first-letter { float: left;font-size: 2em;font-weight: bold;font-family: cursive; padding-right: 2px;}
IE6居然支持!这足以让人惊喜的…..
四、css3 结构性伪类选择器
22.X:nth-child(n)
li:nth-child(3) {color: red;}
:nth-child(n),用于匹配索引值为n的子元素。索引值从1开始。
X:nth-child()用法实际上有三种变化。X:nth-child()更强大的用处在于奇偶匹配。有兴趣的请看《Understanding :nth-child Pseudo-class Expressions》,《CSS3 :nth-child()伪类选择器》
23.X:nth-last-child(n)
li:nth-last-child(2) {color: red;}
:nth-child(n),是从第一个开始算索引,而X:nth-last-child(n)是从最后一个开始算索引。
24.X:nth-of-type(n)
ul:nth-of-type(3) {border: 1px solid black;}
nth-of-type与nth-child的效果是惊人的相似,想要更多的了解nth-of-type请看《Alternative for :nth-of-type() and :nth-child()》,《:nth-of-type(N)》。
25.X:nth-last-of-type(n)
ul:nth-last-of-type(3) {border: 1px solid black;}
:nth-last-child效果相似。
26.X:first-child
ul li:first-child {border-top: none;}
匹配子集的第一个元素。IE7就可以支持了,这个伪类还是非常有用的。
27.X:last-child
ul > li:last-child {color: green;}
与:first-child效果相反
留意IE8支持:first-child,但不支持:last-child。
28.X:only-child
div p:only-child {color: red;}
这个伪类一般用的比较少,比如上述代码匹配的是div下的有且仅有一个的p,也就是说,如果div内有多个p,将不匹配。
29.X:only-of-type
li:only-of-type { font-weight: bold;}
与:only-child类似。
30.X:first-of-type
ul:first-of-type{font-weight: bold;}
等价于:nth-of-type(1),匹配集合元素中的第一个元素。










