更改滚动条样式

Change a scroll bar style

本文关键字:样式 滚动条      更新时间:2023-09-26

请参考此链接查看示例:点击这里

我使用下面的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: scroll;
}
/* Let's get this party started */
::-webkit-scrollbar {
    width: 6px;
}
/* Track */
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
    -webkit-border-radius: 6px;
    border-radius: 6px;
}
/* Handle */
::-webkit-scrollbar-thumb {
    -webkit-border-radius: 6px;
    border-radius: 6px;
    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); 
}

这个css只能改变y轴滚动条的宽度,我怎么能改变x轴滚动条的宽度呢

请帮我解决这个问题

DEMO:

http://plnkr.co/edit/bBEj9xa6TucnJq6scIsq?p =

预览

使用::-webkit-scrollbar {width: 6px; height: 6px;}

检查演示。

http://plnkr.co/edit/bBEj9xa6TucnJq6scIsq?p =

预览

还要注意,基于CSS的滚动条并不适用于所有浏览器。所以,我建议使用基于js的滚动条。

我更喜欢jquery.nicescroll

https://github.com/inuyaksa/jquery.nicescroll

您可以指定高度来增加x滚动条的宽度。例如{}

::-webkit-scrollbar {
  width: 30px;
  height: 30px;
}

你可以在x和y方向设置滚动条的样式。这里是提琴

::-webkit-scrollbar {
  width: 12px;
}
::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}

感谢大家的回答,但解决方案是:

/* Let's get this party started */
::-webkit-scrollbar {
    width: 6px;height:6px;
}