div超出可滚动,自动添加滚动条,自定义滚动条样式

103 阅读1分钟

先看一下最终的效果图吧:

image.png

如何设置呢?

父盒子:

横向超出滚动:overflow-yscroll; 并且设置高度例:height: calc(100% - 36px);

.container {
	overflow-y: scroll;
	height: calc(100% - 36px);
}

自定义滚动条样式

.container::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}
::-webkit-scrollbar-button {
	display: none;
}
::-webkit-scrollbar-track {
	background-color: rgba(70, 166, 255, 0.1);
	display: none;
}
::-webkit-scrollbar-thumb {
	background-color: rgba(70, 166, 255, 0.4);
	border: 2px solid transparent;
	border-radius: 6px;
	background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
	background-color: rgba(0, 0, 0, 0.5);
}