一般我們做按鈕基本上都需要兩張圖片,一張正常狀態(tài)的圖片,一張按下去效果圖片
做這種按鈕思路就是,設(shè)置鏈接a的背景為第一張圖片,a:hover的背景為第二章圖片
HTML代碼:
<a id="theLink"></a>
CSS代碼:
#theLink{
display:block;/*因?yàn)闃?biāo)簽a是內(nèi)鏈元素,所以利用這句話將內(nèi)鏈元素轉(zhuǎn)化成塊狀元素,后面的width和height才起作用*/
width:120px;
height:41px;
margin:0 auto;
background:url(../images/normal.gif) no-repeat;
}
#theLink:hover{background:url(../images/press.gif) no-repeat;}
=========================================================
這節(jié)課,主要給大家介紹第二種思路,其實(shí)也很簡單,首先我們將上面的兩個(gè)圖片合并成一張圖片,如下
其次,將上面的圖片設(shè)置成按鈕的背景
最后,將a:hover的背景向上移動(dòng)41個(gè)像素就OK了
HTML代碼:
<a id="buttonBlock"></a>
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;}
聯(lián)系客服