Home  >  Article  >  Web Front-end  >  How to implement horizontal scrolling of elements using css

How to implement horizontal scrolling of elements using css

王林
王林forward
2020-12-21 09:57:135057browse

How to implement horizontal scrolling of elements using css

Analysis:

Scrolling will occur when the width of the child element is greater than the parent element. Overflow-x: scroll; is horizontal scrolling, and overflow-y: scroll; is vertical scrolling. , horizontal horizontal scrolling is used here according to requirements.

(Learning video sharing: css video tutorial)

html code:

<div class="content">
        <div class="content-list">
            <div class="item" style="margin-right:10px;">
                <div class="amount">
                    <span>2</span>元
                </div>
                <div class="fundInfo">
                    <p class="name">XXXXXX</p>
                    <p>满1000元可用</p>
                </div>                  
            </div>
            <div class="item" style="margin-right:10px;">
                <div class="amount">
                    <span>2</span>元
                </div>
                <div class="fundInfo">
                    <p class="name">XXXXXX</p>
                    <p>满1000元减200</p>
                </div>                  
            </div>
        </div>
    </div>

Main css code:

       .content {
            width: 100%;
            overflow-x: scroll; // 子元素的宽度大于父元素的即可滚动
            overflow-y: hidden;
            border-radius: 4px;
        }
        .content::-webkit-scrollbar {
            display:none
        } // 隐藏滚动条
        .content-list{
            display: -webkit-flex;
            display: -ms-flexbox;
            display: flex;
            float: left;  // 使其脱离文档流 宽度为所有字元素的和
            min-width: 100%;
        }
        .item {
            width: 150px;
            height: 50px;
            display: -webkit-flex;
            display: -ms-flexbox;
            display: flex;
            flex: 3;
            -webkit-align-items: center;
            -ms-flex-align: center;
            align-items: center;
            padding: 0 10px;
        }

Related Recommended: CSS tutorial

The above is the detailed content of How to implement horizontal scrolling of elements using css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete