?今天在定義超鏈接變換a:hover時碰到一些問題,主要是關于圖片大小顯示不正常。
?比如定義了一個CSS樣式:???
研究了老半天,終于發現可以用內補丁padding解決,只要定義一下a,a:hover的padding就可以了,不過發現IE中,a元素padding的top和bottom屬性是不會自動把div給“撐大”的,firefox正常,所以,為了兼容IE,需要在層定義中加入height,就像上面的height:300px;
最后代碼如下:
<style>
#Main

{
}{
width:?300px;
height:300px;
}
#Main?a

{
}{
color:?#006400;
padding:?10px?8px;/*可以有4個參數,表示上右下左延長的距離*/
}
#Main?a:hover

{
}{
color:?Red;
background:?url(/images/botton.gif)?no-repeat?center;/*圖片路徑*/
padding:?10px?8px;/*上下延長距離10px,左右延長距離8px*/
}
</style>其中的距離可以根據圖像大小和具體情況變動。
?比如定義了一個CSS樣式:???
?1
<style>
?2
#Main
?3
{
}{
?4
width:300px;
?5
height:300px;
?6
}
?7
#Main?a
?8
{
}{
?9
color:?#006400;
10
}
11
#Main?a:hover
12
{
}{
13
color:?Red;
14
background:?url(images/botton.gif)?no-repeat?center;
15
}
16
</style>
但是發現定義了沒什么用,因為圖片太大了(60*28px),圖片只顯示了其中一角,然后試著用定義a元素的width和height來解決,發現沒什么用。
?2

?3



?4

?5

?6

?7

?8



?9

10

11

12



13

14

15

16

研究了老半天,終于發現可以用內補丁padding解決,只要定義一下a,a:hover的padding就可以了,不過發現IE中,a元素padding的top和bottom屬性是不會自動把div給“撐大”的,firefox正常,所以,為了兼容IE,需要在層定義中加入height,就像上面的height:300px;
最后代碼如下:























