DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> DIV十CSS布局 >> 布局實例
自訂網頁捲軸樣式的做法
編輯:布局實例     

有些設計稿會要求自訂捲軸樣式。雖然目前仍很難做到跨瀏覽器完全一致,但在特定環境中,還是可以透過 CSS 調整捲軸外觀。

舊版 IE 的捲軸樣式

IE 很早便提供捲軸相關屬性,例如:

scrollbar-arrow-color: color;
scrollbar-face-color: color;
scrollbar-3dlight-color: color;
scrollbar-highlight-color: color;
scrollbar-shadow-color: color;
scrollbar-darkshadow-color: color;
scrollbar-track-color: color;
scrollbar-base-color: color;

這些屬性可以調整箭頭、軌道、亮邊與陰影等部分,但其他瀏覽器支援度有限。

WebKit 的偽元素做法

在 WebKit 核心瀏覽器中,可以使用偽元素來自訂捲軸:

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

常見的偽元素包含:

  • ::-webkit-scrollbar:整體捲軸。
  • ::-webkit-scrollbar-track:軌道。
  • ::-webkit-scrollbar-thumb:滑桿。
  • ::-webkit-scrollbar-button:上下按鈕。

此外,也可以搭配 :horizontal、:vertical、:decrement、:increment 等狀態,進一步控制不同部位。

實務建議:自訂捲軸可以提升視覺一致性,但仍應保留清楚的可操作狀態,例如 hover、active、disabled,避免影響可用性。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved