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

How to implement horizontal scrolling of elements using css

王林
Release: 2020-12-21 09:57:13
forward
5085 people have browsed it

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>
Copy after login

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;
        }
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template