html自定义滚动条

鼠标滑入展示滚动条

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值