查看演示
我們用 A 包含一個 SPAN 標簽來實現(xiàn)此效果:
HTML:
<a class=”button” href=”#”><span>按鈕文字</span></a>
設置按鈕樣式:
<style type=”text/css”>
a.button {
background: transparent url(‘bg_button_a.gif’) no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 24px;
margin-right: 6px;
padding-right: 18px; /* sliding doors padding */
text-decoration: none;
}
a.button span {
background: transparent url(‘bg_button_div.gif’) no-repeat;
display: block;
line-height: 14px;
padding: 5px 0 5px 18px;
}
</style>
為按鈕添加點擊樣式:
<style type=”text/css”>
a.button:active {background-position: bottom right; color: #000; outline: none; /* hide dotted outline in Firefox */ }
a.button:active span { background-position: bottom left; padding: 6px 0 4px 18px; /* push text down 1px */ }
</style>
由于 IE 下點擊后不能還原到默認狀態(tài),因此,我們需要在標簽里添加一段代碼:
<a class="button" href="#" onclick="this.blur(); return false;"><span>按鈕文字</span></a>
如果你需要用它提交表單(FORM),那么可以在 onclick 里面添加一個提交語句,如:document.forms[‘theForm’].submit();
新聞熱點
疑難解答