当前位置:网站首页 > 网站建设教程 > HTML教程 > 正文

html自定义滚动条(整理)

教程管理员 发布于2023-09-30 13:56 HTML教程 129

简介: 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>自定义滚动条</title>
        <style>
            .scroll-x {
                overflow-x: scroll;
                white-space: nowrap;
                width: 300px;
            }

            .scroll-x>.item {
                width: 80px;
                height: 80px;
                display: inline-block;
                line-height: 80px;
                font-size: 60px;
                color: #fff;
                text-align: center;
            }

            .scroll-x>.item:nth-child(2n) {
                background-color: #00f;
            }

            .scroll-x>.item:nth-child(2n+1) {
                background-color: #0fa;
            }
            .scroll-x::-webkit-scrollbar {
                width: 12px;
                height: 12px;
                color: #dddddd;
            }

            .scroll-x::-webkit-scrollbar-track {
                border-radius: 12px;
                box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
                background-color: #dddddd;
                margin: 100px;  /* 很神奇,您试下-修改大小 */
            }

            .scroll-x::-webkit-scrollbar-thumb {
                border-radius: 12px;
                background-color: #ff5153;
            }
        </style>
    </head>

    <body>
        <div class="scroll-x">
            <div class="item">1</div>
            <div class="item">2</div>
            <div class="item">3</div>
            <div class="item">4</div>
            <div class="item">5</div>
            <div class="item">6</div>
            <div class="item">7</div>
        </div>
    </body>

</html>

image


琼ICP备09004296号-12