滚动条样式表

时间:2012-05-15 00:13:34

标签: css

我有以下样式表,它更改了Web浏览器滚动条的颜色。 但问题是它改变了所有滚动条,包括浏览器的主滚动条。

我想将此仅应用于溢出区域。感谢

例如,

<div style="overflow: scroll">this area</div>

/* Turn on a 13x13 scrollbar */
::-webkit-scrollbar {
    width: 13px;
    height: 13px;
}

::-webkit-scrollbar-button:vertical {
    background-color: red;
    border: 1px dashed blue;
}

/* Turn on single button up on top, and down on bottom */
::-webkit-scrollbar-button:start:decrement,
::-webkit-scrollbar-button:end:increment {
    display: block;
}

/* Turn off the down area up on top, and up area on bottom */
::-webkit-scrollbar-button:vertical:start:increment,
::-webkit-scrollbar-button:vertical:end:decrement {
    display: none;
}

/* Place The scroll down button at the bottom */
::-webkit-scrollbar-button:vertical:increment {
    background-color: black;
    border: 1px dashed blue;
}

/* Place The scroll up button at the up */
::-webkit-scrollbar-button:vertical:decrement {
    background-color: purple;
    border: 1px dashed blue;
}

::-webkit-scrollbar-track:vertical {
    background-color: blue;
    border: 1px dashed pink;
}

/* Top area above thumb and below up button */
::-webkit-scrollbar-track-piece:vertical:start {
    border: 1px solid #000;
}

/* Bottom area below thumb and down button */
::-webkit-scrollbar-track-piece:vertical:end {
    border: 1px dashed pink;
}

/* Track below and above */
::-webkit-scrollbar-track-piece {
    background-color: green;
}

/* The thumb itself */
::-webkit-scrollbar-thumb:vertical {
    height: 50px;
    background-color: yellow;
}

/* Corner */
::-webkit-scrollbar-corner:vertical {
    background-color: black;
}

/* Resizer */
::-webkit-scrollbar-resizer:vertical {
    background-color: gray;
}

1 个答案:

答案 0 :(得分:2)

请参阅http://jsfiddle.net/Bghcr/1/

  • 为要应用样式的元素指定类名
  • 使用类名缩小滚动条选择器的范围

HTML

<div class="custom-scroll">this area</div>​

CSS

.custom-scroll {
    width: 300px;
    height: 300px;
    overflow: scroll;
    border: 1px solid silver;
}

.custom-scroll::-webkit-scrollbar {
    width: 13px;
    height: 13px;
}

.custom-scroll::-webkit-scrollbar-button:vertical {
    background-color: red;
    border: 1px dashed blue;
}

/* ETC */

其他注释

相关问题