1.僞類選擇器css
在CSS中,最經常使用的僞類選擇器是使用在a(錨)元素上的幾種選擇器,它們的使用方法以下:spa
a:link{color:#FF0000;text-decoration:none}it
a:visited{color:#FF0000;text-decoration:none}io
a:hover{color:#FF0000;text-decoration:none}方法
a:active{color:#FF0000;text-decoration:none}樣式
2.僞元素選擇器僞元素
僞元素選擇器不是針對真正的元素使用的選擇器,而是針對CSS中已經定義好的僞元素使用的選擇器,在CSS中主要有以下四個僞元素選擇器:vi
(1)first-line僞元素選擇器co
<style type=text/css>僞類
p:first-line{color:#0000FF};
</style>
(2)first-letter僞元素選擇器
向某個元素中的文字的首字母(歐美文字)或第一個字(中日等漢字)使用樣式。
<style type=text/css>
p:first-letter{color:#0000FF};
</style>
(3)before僞元素選擇器
before僞元素選擇器擁有在某個元素以前插入一些內容,使用方法以下:
元素:before{
content:""
}
<style type="text/css">
li:before{content:"hello"}
</style>
(4)after僞元素選擇器
<style type="text/css">
li:after{
content:"hello";
font-size:12px;
color:red;
}
</style>