做後台或表單密集的頁面時,按鈕樣式往往是最枯燥的一環。這份範例收錄了五十個風格各異的按鈕,從扁平到擬物、從純文字到圖示搭配,可以直接挑喜歡的用在專案裡。
效果預覽:https:///keleyi/phtml/divcss/7.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>多個漂亮的按鈕樣式和圖片集合</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="https:///keleyi/phtml/divcss/7/button.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div style="width:800px;margin:0px auto">
<span style="font-size:18px; font-weight:bold; text-align:center; line-height:25px; color:#000; width:100%">漂亮的按鈕樣式和圖片集合</span>
</div>
<form id="form-keleyi-com" name="form-keleyi-com" action="https://" target="_blank">
<div class="d1">
<input type="submit" value="Update" onmouseover="this.style.borderColor='#75cd02'" onmouseout="this.style.borderColor='#dcdcdc'" class="btn1 pbtn1" />
<input type="submit" value="Delete" onmouseover="this.style.borderColor='#f76b00'" onmouseout="this.style.borderColor='#dcdcdc'" class="btn2 pbtn1" />
<input type="submit" value="Reset" onmouseover="this.style.borderColor='#86c6f7'" onmouseout="this.style.borderColor='#dcdcdc'" class="btn3 pbtn1" />
<input type="button" value="Submit" class="btn4" />
<input type="button" value="Button" class="btn5" />
<input type="button" value="Add Group" class="btn6" onmouseover="this.style.backgroundPosition='left -35px'" onmouseout="this.style.backgroundPosition='left top'" />
<button type="button" class="pbtn2"><img src="https:///keleyi/phtml/divcss/7/image/button/register.gif" alt="register" /></button>
<button type="button" class="pbtn2 btn8"><img src="https:///keleyi/phtml/divcss/7/image/button/favorite.gif" alt="favorite" /></button>
<button type="button" class="pbtn2 btn9"><img src="https:///keleyi/phtml/divcss/7/image/button/help.gif" alt="help" /></button>
<input type="button" class="btn10" onmouseover="this.style.backgroundPosition='left -40px'" onmouseout="this.style.backgroundPosition='left top'" value="Submit" />
<input type="button" class="btn11" onmouseover="this.style.backgroundPosition='left -40px'" onmouseout="this.style.backgroundPosition='left top'" value="Submit" />
<input type="button" class="btn12" onmouseover="this.style.backgroundPosition='left -40px'" onmouseout="this.style.backgroundPosition='left top'" value="Submit" />
<button type="button" class="pbtn3"></button>
<button type="button" class="pbtn3 btn14"></button>
<button type="button" class="pbtn3 btn15"></button>
<button type="button" class="btn16"></button>
<button type="button" class="btn17"></button>
<button type="button" class="btn18"></button>
<input type="button" class="btn22" value="Downloads!" onmouseover="this.style.backgroundPosition='left -42px'" onmouseout="this.style.backgroundPosition='left top'" />
<input type="button" class="btn23" value="Call me !!" onmouseover="this.style.backgroundPosition='left -45px'" onmouseout="this.style.backgroundPosition='left top'" />
</div>
<div class="d2">
<input type="button" class="btn24" value="Closed" onmouseover="this.style.backgroundPosition='left -50px'" onmouseout="this.style.backgroundPosition='left top'" />
<input type="button" class="btn25" value="Submit" onmouseover="this.style.backgroundPosition='left -49px'" onmouseout="this.style.backgroundPosition='left top'" />
<input type="button" class="btn27" value="Online" />
<input type="button" class="btn28" value="Rss Feed" />
<input type="button" class="btn30" value="Button" />
<input type="button" class="btn31" value="Search" />
<input type="button" class="btn32" value="Search" />
<input type="button" class="btn34" value="Button" />
<input type="button" class="btn35" value="Button" onmouseover="this.style.backgroundPosition='left -40px'" onmouseout="this.style.backgroundPosition='left top'" />
<input type="button" class="btn36" value="Button" onmouseover="this.style.backgroundPosition='left -38px'" onmouseout="this.style.backgroundPosition='left top'" />
</div>
<div class="d3">
<input type="button" class="btn37" value="Hard rock" />
<input type="button" class="btn38" value="Your profile" />
<input type="button" class="btn39" value="British" />
<input type="button" class="btn40" value="Development" />
<input type="button" class="btn42" value="Find out more" />
<input type="button" class="btn43" value="Enterprise Gateway" />
<input type="button" class="btn44" value="Comments" />
<input type="submit" class="btn45" value="Submit" onmouseover="this.style.backgroundPosition='left -75px';this.style.color='#bcf1a7';" onmouseout="this.style.backgroundPosition='left top';this.style.color='#ffafaf';" />
<input type="submit" class="btn47" value="New user interface" onmouseover="this.style.backgroundPosition='left -78px';this.style.color='#a15507';" onmouseout="this.style.backgroundPosition='left top';this.style.color='#097b96';" />
</div>
</form>
</body>
</html>
精靈圖(sprite)位移:大量按鈕的 hover 效果是靠 onmouseover 改變 backgroundPosition 完成的。做法是將同一顆按鈕的正常態與 hover 態上下拼接在同一張圖裡,滑入時把背景往上位移固定的像素數,就能切換到下一個狀態。這種做法只發一次圖片請求,也不需要預先載入 hover 圖而產生閃爍。
圖示圖片鑲嵌:像 register.gif、favorite.gif、help.gif 這類,直接用 <img> 放進 <button> 裡,讓圖示與文字能各自獨立對齊。
邊框顏色過渡:btn1 到 btn3 這組在滑入時只改 borderColor,用綠、橘、藍分別暗示「新增/刪除/重設」的語意,是很低成本的狀態提示。
實務建議:這些 onmouseover 內聯寫法在當年很普遍,但以今日標準來看,把它們搬進 CSS 的 :hover 規則裡會更好維護,也能用 transition 做出平滑過渡。此外,純裝飾性的圖示按鈕記得補上 aria-label,讓螢幕閱讀器能讀出用途。