經典藍色按鈕樣式代碼
.blue-button {
font-family: "Tahoma", "SimSun", sans-serif;
font-size: 9pt;
color: #003366;
border: 1px solid #93bee2;
background-image: url(../images/blue_button_bg.gif); /* 漸變背景圖 */
background-color: #ffffff; /* 圖片加載前備用色 */
cursor: pointer; /* hand 非標準,用 pointer */
font-style: normal;
/* 現代增強 */
border-radius: 3px;
padding: 4px 12px;
text-decoration: none;
display: inline-block;
transition: all 0.2s ease;
}
.blue-button:hover {
background-color: #e8f4ff;
border-color: #1a8cdd;
color: #0056a0;
}
.blue-button:active {
background-color: #d0e8f8;
transform: translateY(1px);
}
HTML 使用示例
<button class="blue-button">提交</button>
<a href="#" class="blue-button">鏈接按鈕</a>
<input type="submit" class="blue-button" value="確定">
現代純 CSS 實現(無圖片)
.blue-button-modern {
font-family: "Tahoma", "Microsoft YaHei", sans-serif;
font-size: 14px;
color: #fff;
background: linear-gradient(180deg, #4a90d9 0%, #2d6ec7 100%);
border: 1px solid #1a5bb8;
border-radius: 4px;
padding: 8px 20px;
cursor: pointer;
text-shadow: 0 -1px 0 rgba(0,0,0,0.2);
box-shadow:
inset 0 1px 0 rgba(255,255,255,0.2),
0 1px 2px rgba(0,0,0,0.1);
transition: all 0.15s ease;
}
.blue-button-modern:hover {
background: linear-gradient(180deg, #5a9fe0 0%, #3d7ed9 100%);
box-shadow:
inset 0 1px 0 rgba(255,255,255,0.3),
0 2px 4px rgba(0,0,0,0.15);
}
.blue-button-modern:active {
background: linear-gradient(180deg, #2d6ec7 0%, #1a5bb8 100%);
box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
按鈕狀態完整定義
| 狀態 | 偽類 | 關鍵樣式變化 |
| 默認 | 無 | 基礎漸變、邊框、陰影 |
| 懸停 | :hover | 亮化漸變、加深邊框、增大陰影 |
| 聚焦 | :focus | 外發光輪廓 outline: 2px solid #4a90d9; outline-offset: 2px; |
| 按下 | :active | 反轉漸變、內陰影、向下位移 1px |
| 禁用 | :disabled | 降低不透明度 opacity: 0.6、禁用指針 cursor: not-allowed |
無障礙增強
.blue-button:focus-visible {
outline: 2px solid #4a90d9;
outline-offset: 2px;
}
/* 鍵盤操作提示 */
.blue-button::-moz-focus-inner { border: 0; padding: 0; } /* Firefox 內部邊距重置 */
相關延伸閱讀
CSS 按鈕樣式代碼大全:多種風格、尺寸、圖標按鈕