鼠标滑入展示滚动条
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<style>
.right {
max-height: 80px;
overflow-y: auto;
width: 200px;
}
p {
line-height: 20px;
}
.right::-webkit-scrollbar {
width: 0px;
height: 0px;
}
.right:hover::-webkit-scrollbar {
width: 4px;
height: 14px;
background-color: #ffffff;
cursor: pointer;
}
.right::-webkit-scrollbar-thumb {
width: 4px;
border: 0 none;
border-radius: 4px;
background-color: #DCDCDC;
cursor: pointer;
}
.right::-webkit-scrollbar-button {
/* background-color: pink; */
background-color: transparent;
height: 10px;
}
</style>
</head>
<body>
<div class="right">
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
</div>
</body>
</html>
基础样例学习
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.wrap {
display: flex;
position: absolute;
height: 100%;
width: 100%;
}
p {
text-align: center;
}
.left {
width: 30%;
height: 50%;
background-color: pink;
overflow: auto;
}
.right {
width: 70%;
height: 80%;
background-color: plum;
overflow: auto;
}
/* 修改滚动条样式 */
.left::-webkit-scrollbar {
/*
width height分别对应竖向滚动条和横向滚动条
*/
width: 5px;
height: 5px;
background-color: #ffffff;
}
.right::-webkit-scrollbar {
width: 20px;
height: 20px;
background-color: #ffffff;
}
/* 修改滚动条中的小滑块 */
.left::-webkit-scrollbar-thumb {
width: 10px;
border-radius: 5px;
background-color: royalblue;
}
.right::-webkit-scrollbar-thumb {
width: 10px;
border-radius: 5px;
background-color: royalblue;
}
/* 定义滚动条的轨道 */
.left::-webkit-scrollbar-track {
background-color: red;
}
.right::-webkit-scrollbar-track {
background-color: greenyellow;
}
/* 定义轨道两端的按钮 */
.left::-webkit-scrollbar-button {
background-color: green;
}
.right::-webkit-scrollbar-button {
background-color: hotpink;
}
/*
给小滑块添加hover事件,鼠标悬浮在滑块上面的样式
*/
.left::-webkit-scrollbar-thumb:hover {
background-color: hotpink;
}
.right::-webkit-scrollbar-thumb:hover {
background-color: red;
}
</style>
</head>
<body>
<div class="wrap">
<div class="left">
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
<p>1</p>
</div>
<div class="right">
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
<p>2</p>
</div>
</div>
</body>
</html>