現代瀏覽器(Chrome、Edge、Safari、Opera)支援透過 ::-webkit-scrollbar 系列偽元素完整客製化捲軸外觀。本文提供可直接套用的極簡深色捲軸 CSS。
/* 整體捲軸寬高 */
::-webkit-scrollbar { width: 12px; height: 12px; }
/* 軌道 */
::-webkit-scrollbar-track {
background: #1e1e1e;
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
/* 滑塊 */
::-webkit-scrollbar-thumb {
background: rgba(0,0,0,0.1);
border-radius: 10px;
border: 3px solid #1e1e1e;
box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }
::-webkit-scrollbar-thumb:active { background: rgba(0,0,0,0.5); }
/* 非作用中視窗 */
::-webkit-scrollbar-thumb:window-inactive { background: rgba(255,0,0,0.4); }
/* 角落 */
::-webkit-scrollbar-corner { background: #1e1e1e; }
/* 縱向/橫向專屬 */
::-webkit-scrollbar:vertical { width: 12px; }
::-webkit-scrollbar:horizontal { height: 12px; }
* {
scrollbar-width: thin; /* auto | thin | none */
scrollbar-color: #444 #1e1e1e; /* thumb track */
}
僅針對特定容器:
.custom-scroll::-webkit-scrollbar { width: 8px; }
.custom-scroll::-webkit-scrollbar-track { background: #f1f1f1; }
.custom-scroll::-webkit-scrollbar-thumb { background: #888; border-radius: 4px; }
.custom-scroll::-webkit-scrollbar-thumb:hover { background: #555; }
<div class="custom-scroll" style="overflow:auto; max-height:300px;">...長內容...</div>
scrollbar-width: none; -ms-overflow-style: none; + ::-webkit-scrollbar { display: none; }