早期依賴圖片 Sprite、滑動門;CSS3 帶來 `border-radius`、`box-shadow`、`gradient`、`transition`、`transform`,實現**零圖片、可縮放、可主題化、易維護**的按鈕系統。
.btn-flat {
padding: 10px 24px; border-radius: 4px;
background: linear-gradient(135deg, #42a5f5, #1e88e5);
color: #fff; font-weight: 500; border: none; cursor: pointer;
box-shadow: 0 2px 5px rgba(30,136,229,.4);
transition: transform .1s, box-shadow .1s;
}
.btn-flat:hover { box-shadow: 0 4px 12px rgba(30,136,229,.5); }
.btn-flat:active { transform: translateY(1px); box-shadow: 0 1px 3px rgba(30,136,229,.4); }
.btn-glow {
background: linear-gradient(90deg, #ff6b6b, #ee5a5a);
box-shadow: 0 0 0 rgba(238,90,90,.4);
animation: pulse 2s infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 20px 5px rgba(238,90,90,.6); } }
.btn-3d {
background: linear-gradient(#4a90d9, #3070b0);
box-shadow: 0 4px 0 #205080, 0 6px 4px rgba(0,0,0,.2);
transition: all .05s;
}
.btn-3d:active { transform: translateY(4px); box-shadow: 0 0 0 #205080, 0 2px 2px rgba(0,0,0,.2); }
.btn-neu {
background: #e0e5ec; border-radius: 12px;
box-shadow: 8px 8px 16px #bebebe, -8px -8px 16px #fff;
transition: box-shadow .2s;
}
.btn-neu:active { box-shadow: inset 4px 4px 8px #bebebe, inset -4px -4px 8px #fff; }
.btn-border {
position: relative; background: transparent; border: 2px solid transparent;
background-clip: padding-box; /* 關鍵:背景不繪到邊框下 */
}
.btn-border::before {
content: ''; position: absolute; inset: -2px;
border-radius: inherit;
background: linear-gradient(90deg, #00f, #0ff, #0f0, #ff0, #f0f, #00f);
background-size: 400%; z-index: -1; animation: borderFlow 3s linear infinite;
}
@keyframes borderFlow { to { background-position: 400% 0; } }
.btn-icon { display: inline-flex; align-items: center; gap: 8px; }
.btn-icon svg { width: 1em; height: 1em; transition: transform .2s; }
.btn-icon:hover svg { transform: translateX(3px); }
.btn-github { background: #24292e; color: #fff; }
.btn-google { background: #fff; color: #3c4043; border: 1px solid #dadce0; }
.btn-gitlab { background: #fc6d26; color: #fff; }
.btn-glass {
background: rgba(255,255,255,.2); backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,.3); box-shadow: 0 8px 32px rgba(0,0,0,.1);
}
.btn-loading { position: relative; color: transparent; pointer-events: none; }
.btn-loading::after {
content: ''; position: absolute; inset: 0; border-radius: inherit;
background: repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(255,255,255,.3) 10px, rgba(255,255,255,.3) 20px);
animation: stripe 1s linear infinite;
}
<button class="btn btn-primary" type="button" aria-pressed="false">
<svg aria-hidden="true">...</svg> 儲存
</button>
CSS 中 `:focus-visible` 保證鍵盤聚焦可見,`disabled` 狀態自動降低對比度與 `cursor: not-allowed`。