css implements a custom scroll bar @莫成尘

Look at the code first, just copy and use, the following code can be copied and pasted to use (I will explain the code in the form of comments, you will see the following effects). The original scroll bar is relatively square, not sleek enough, and can't satisfy our aesthetics to a large extent. Sometimes its style needs to be modified.

滚动条的高度将随着内容的多少自适应

Custom scroll bar

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
</head>
<style type="text/css">
	.Count-box{
    
     //最外层盒子
	  height: 220px;
	  width: 227px;
	  overflow: auto;
	  display: inline-block;  /* 测试效果 使用时请删除  */
	}
	.countSon{
    
     //站位元素
		height: 40px;
		margin: 8px;
		line-height: 40px;
		text-align: center;
	}
	/* 第一个 */
	.Count-box-zero::-webkit-scrollbar {
    
    
	  width:6px;
	  height:220px;     
	}
	.Count-box-zero::-webkit-scrollbar-thumb {
    
    
	  border-radius: 3px;
	  box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
	  background: rgba(0,0,0,0.2);
	}
	.Count-box-zero::-webkit-scrollbar-track {
    
    
	  box-shadow: inset 0 0 0px rgba(0,0,0,0.2);
	  border-radius: 0;
	  background: rgba(0,0,0,0.1);
	}
	/* 第二个 */
	.Count-box-one::-webkit-scrollbar {
    
    
	  width:6px;
	  height:220px;     
	}
	.Count-box-one::-webkit-scrollbar-thumb {
    
    
	  border-radius: 3px;
	  box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
	  background: red;
	}
	.Count-box-one::-webkit-scrollbar-track {
    
    
	  box-shadow: inset 0 0 0px rgba(0,0,0,0.2);
	  border-radius: 0;
	  background: skyblue;
	}
	/* 第三个  无任何效果 */
</style>
<body>
	<div class="Count-box-zero Count-box">
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
	</div>
	<div class="Count-box-one Count-box">
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
	</div>
	<div class="Count-box-two Count-box">
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
		<div class="countSon">占位内容</div>
	</div>
</body>
</html>

Additional and useful information that may appear has been annotated

Guess you like

Origin blog.csdn.net/weixin_47821281/article/details/114016009