一、伪类与伪元素
伪类与伪元素的区别在于影响文档的方式不同,伪类就像给文档元素添加类,而伪元素效果就像将元素插入到了文档中。
eg:
h1:hover{font-size:250%;}
<h1>媚媚你好!</h1>
h1::first-letter{font-size: 250%;}<h1>媚媚你好!</h1>
下面列出主要的伪类和伪元素
1、伪类(pseudo-class):
:link - 未访问过的链接;
:visited - 访问过的链接;
:hover - 鼠标悬停的元素;
:focus - 获取焦点的元素;
:active - 激活的元素(例如一个被单击的链接元素);
:first-child - 某一元素里的第一个子元素;
:lang() - 根据元素的lang属性确定的元素;
CSS3添加如下伪类,截止2012年,他们还未被广泛支持:
:target
:root
:nth-child()
:nth-of-type()
:nth-last-of-type()
:first-of-type
:last-of-type
:only-of-type
:only-child
:last-child
:empty
:not()
:enabled
:disabled
:checked
2、伪元素(pseudo-element)
::first-link
::first-letter
::before
::after