美文网首页
flex自适应横向滚动区域

flex自适应横向滚动区域

作者: B612的末影人 | 来源:发表于2022-04-10 05:09 被阅读0次

    效果如图

    2022-04-10 05.04.45.gif
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>Document</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            * {
                margin: 0;
                padding: 0;
            }
    
            body {
                height: 100vh;
                width: 100vw;
                -webkit-touch-callout: none;
                -moz-user-select: none; /*火狐*/
                -webkit-user-select: none; /*webkit浏览器*/
                -ms-user-select: none; /*IE10*/
                user-select: none;
                display: flex;
            }
    
            .reader {
                position: relative;
                background: bisque;
                flex: 1;
                display: flex;
                overflow: hidden;
                padding: 20px;
            }
    
            .scroll-view {
                position: relative;
                flex: 1;
                display: flex;
                overflow-x: auto;
                align-items: center;
                background: #333333;
            }
    
            .anything {
                background: aliceblue;
                height: 100px;
                width: 200px;
                flex: none;
                display: flex;
                align-items: center;
                justify-content: center;
    
            }
    
            .anything:nth-child(2n) {
                background: #0def53;
            }
    
        </style>
    </head>
    <body>
    <div class="reader">
        <div>
            <p>随机宽度的文字</p>
        </div>
        <div class="scroll-view">
            <div class="anything">
                <p>居中</p>
            </div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
            <div class="anything"></div>
        </div>
    </div>
    </body>
    </html>
    

    使用时只需要把scroll-view移动到需要自适应滚动撑满的地方就可以
    这是纵向例子:flex自适应滚动区域

    相关文章

      网友评论

          本文标题:flex自适应横向滚动区域

          本文链接:https://www.haomeiwen.com/subject/raomsrtx.html