僞類的語法:css
selector : pseudo-class {property: value}
CSS 類也可與僞類搭配使用:html
selector.class : pseudo-class {property: value}
在支持 CSS 的瀏覽器中,連接的不一樣狀態均可以不一樣的方式顯示,這些狀態包括:活動狀態,已被訪問狀態,未被訪問狀態,和鼠標懸停狀態。瀏覽器
a:link {color: #FF0000} /* 未訪問的連接 */ a:visited {color: #00FF00} /* 已訪問的連接 */ a:hover {color: #FF00FF} /* 鼠標移動到連接上 */ a:active {color: #0000FF} /* 選定的連接 */
在下面的例子中,選擇器匹配做爲任何元素的第一個子元素的 p 元素:spa
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p:first-child { color: red; } </style> </head> <body> <p>some text</p> <p>some text</p> </body> </html>
效果:3d
僞元素的語法:code
selector:pseudo-element {property:value;}
CSS 類也能夠與僞元素配合使用:htm
selector.class:pseudo-element {property:value;}
僞元素種類:blog