CSS基礎(chǔ)教學(xué)之偽類選擇器
CSS偽類選擇器:為超連結(jié)加的樣式(連結(jié)的不同狀態(tài)加樣式)
一個超鏈接,有四個狀態(tài):
正常狀態(tài)(:link):滑鼠沒放上先前連結(jié)的樣式。
放上狀態(tài)(:hover):滑鼠放到連結(jié)上時的樣式。
啟動狀態(tài)(:active):按住滑鼠左鍵不放開的樣式,這個狀態(tài)特別短暫。
訪問過的狀態(tài)(:visited):按下滑鼠左鍵,並彈起,這時的樣式效果。
在平常工作中,會使用以下寫法,來為連結(jié)加上不同的樣式:
a:link, a:visited{ color:#444; text-decoration: none; } ?//將「正常狀態(tài)」和「造訪過的狀態(tài)」合而為一。
a:hover{ color:#990000; text-decoration:underline; } ?//「滑鼠放上」單做一個效果
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> </head> <style type="text/css"> .box { height:30px; border:1px solid red; padding:10px; } .box a:link,.box a:visited{color:#66ff88;text-decoration:none; }/*將“正常狀態(tài)”和“訪問過的狀態(tài)”合二為一。*/ .box a:hover{color:#ff0000;text-decoration:underline;}/*“鼠標(biāo)放上”單做一種效果*/ </style> <body> <div class="box"> <a href="#">歡迎來到php.cn</a>| <a href="#">首頁</a>| <a href="#">課程</a>| <a href="#">問答</a>| <a href="#">手記</a> </div> </body> </html>