Css 單圖片按鈕實例(css 圖片變換)


1.場景描述,根據鼠標的移動,動態的切換按鈕圖片。

2.方法1,准備兩張120*41的圖片,一張正常狀態圖片,一張按下效果圖片。在鼠標放在的按鈕上設置按下圖片,移開又恢復到正常狀態圖片。缺點:在網頁上按下的圖片需要下載,會出現鼠標移動上去,未馬上切換效果。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>兩張圖片按鈕實例</title>
<style type="text/css">
#theLink{
    display:block;
    width:120px;
    height:41px;
    margin:0 auto;
    background:url(images/normal.gif) no-repeat;
}
#theLink:hover{background:url(images/press.gif) no-repeat;}
</style>
</head>

<body>
<a id="theLink"></a>
</body>
</html>

 

3.方法2,整個設置一張圖片,120*82,根據顯示的需要,動態的截取顯示尺寸。優勢:在網頁上可以一次下載完全一張圖片,節約資料效率。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>單張圖片按鈕實例</title>
<style type="text/css">
#theLink{
    display:block;
    width:120px;
    height:41px;
    margin:0 auto;
    background:url(images/buttonBG.gif) no-repeat;
}
#theLink:hover{ background:url(images/buttonBG.gif) no-repeat 0 -41px;}
</style>
</head>

<body>
<a id="theLink"></a>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM