link,hover,active三種按鍵狀態,存放三張圖片css
缺點:html
資源只有在被使用時,纔會被加載。url
頁面第一次加載時,會出現短暫的延遲閃爍,形成一次不佳的用戶體驗。spa
圖片整合技術 CSS-Sprite 雪碧圖:code
將三張圖片整合爲一張圖片,在不一樣的僞類中經過設置 background-position 來切換圖片。htm
一次請求一次加載,一次加載一張圖片,至關於多張圖片。blog
優點:圖片
實例效果:utf-8
html代碼:資源
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>湖南城市學院</title> <link rel="stylesheet" type="text/css" href="css/hncu.css" /> </head> <body> <div id="hncu_header"> <div id="hncu_search"> <a href="#" id="search_btn"></a> </div> </div> <ul id="hncu_nav"> <li> <a href="#">首頁</a> </li> <li> <a href="#">新聞</a> </li> <li> <a href="#">聯繫</a> </li> <li> <a href="#">關於</a> </li> </ul> <div id="hncu_content"> <div id="hncu_left"></div> <div id="hncu_center"></div> <div id="hncu_right"></div> </div> <div id="hncu_footer"> </div> </body> </html>
css源代碼:
@charset "utf-8"; *{ margin: 0px; padding: 0px; } body{ background-color: #bfc; } #hncu_header{ width: 1000px; height: 200px; background-color: skyblue; margin: 10px auto 10px; } #hncu_search{ width: 360px; height: 180px; background-color: skyblue; overflow:hidden; zoom:1; margin: 10px auto 10px; float: right; } #search_btn { display: block; width: 93px; height: 29px; background-color: skyblue; background-repeat: no-repeat; position: relative; left: 260px; top: 144px; } #search_btn:link { background-image: url(../img/btn.png); } #search_btn:hover { background-position: -93px 0px; } #search_btn:active { background-position: -186px 0px; } #hncu_nav{ width: 1000px; height: 70px; background-color: blue; list-style:none; margin:0px auto 10px; overflow:hidden; zoom: 1; } #hncu_nav li{ width: 25%; height: 70px; float: left; } #hncu_nav a{ width: 100%; height: 70px; color: white; line-height: 70px; text-align: center; text-decoration: none; float: left; } #hncu_nav a:link{ background-color: blue; } #hncu_nav a:visited{ background-color: blue; } #hncu_nav a:hover{ background-color: red; } #hncu_nav a:active{ color: blue; } #hncu_content{ width: 1000px; height: 600px; background-color: yellow; margin:0px auto 10px; } #hncu_left{ width: 200px; height: 500px; background-color: green; margin-top:50px; float:left; } #hncu_center{ width: 580px; height: 500px; background-color: #bfc; margin-top:50px; margin-right: 10px; margin-left: 10px; float:left; } #hncu_right{ width: 200px; height: 500px; background-color: pink; margin-top:50px; float:left; } #hncu_footer{ width:1000px; height:200px; background-color:skyblue; margin:0px auto 10px; }