Quantcast
Viewing all articles
Browse latest Browse all 28

如何设置 WebKit 浏览器滚动条属性

为了增加页面的视觉效果,基于WebKit的浏览器可以通过定义伪类 ::-webkit-scrollbar 属性来设置滚动条的属性(大小,颜色,位置,背景等)。注:请使用Chrome浏览器来体验滚动条效果,不支持IE Opera Firefox。

设置 WebKit 浏览器滚动条属性的7条 CSS 伪类:

::-webkit-scrollbar { /* 1 */ }
::-webkit-scrollbar-button { /* 2 */ }
::-webkit-scrollbar-track { /* 3 */ }
::-webkit-scrollbar-track-piece { /* 4 */ }
::-webkit-scrollbar-thumb { /* 5 */ }
::-webkit-scrollbar-corner { /* 6 */ }
::-webkit-resizer { /* 7 */ }

Image may be NSFW.
Clik here to view.
如何设置 WebKit 浏览器滚动条属性

11种滚动条类型

:horizontal(水平方向)和:vertical(垂直方向)使用的最频繁,其他很少使用。

:horizontal
:vertical
:decrement
:increment
:start
:end
:double-button
:single-button
:no-button
:corner-present
:window-inactive

滚动条设置示例:

Image may be NSFW.
Clik here to view.
如何设置 WebKit 浏览器滚动条属性

CSS代码:

/* For the “inset” look only */
html {
overflow: auto;
}
body {
position: absolute;
top: 20px;
left: 20px;
bottom: 20px;
right: 20px;
padding: 30px;
overflow-y: scroll;
overflow-x: hidden;
}

/* Let’s get this party started */
::-webkit-scrollbar {
width: 12px;
}

/* Track */
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
-webkit-border-radius: 10px;
border-radius: 10px;
}

/* Handle */
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(255,0,0,0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(255,0,0,0.4);
}
/* Handle */
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(255,0,0,0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(255,0,0,0.4);
}

如何设置 WebKit 浏览器滚动条属性,首发于任鸟飞网站设计教程网 - 关注网站网页设计、网站推广及网站赚钱


Viewing all articles
Browse latest Browse all 28

Trending Articles