Home Web Front-end CSS Tutorial CSS Flex layout for seamless scrolling

CSS Flex layout for seamless scrolling

Jul 21, 2020 pm 12:43 PM
flex Seamless scrolling

CSS Flex layout for seamless scrolling

This article mainly introduces the sample code of flex layout to achieve seamless scrolling and shares it with everyone. The details are as follows:

Demonstration of the case

flex layout

The so-called flex layout is the flexible box layout. This layout is more commonly used on mobile terminals, but with the development of browsers The version is updated, and flex layout is becoming more and more commonly used due to its own advantages.

Idea:

  • First analyze the structure of this small demo, the upper and lower structures, we can use a container to wrap it (the so-called big box).

  • The top is a navigation, and the top is a ul. Below we can use two ps, 100% of the width, and customized height.

  • Next we will open the model and remember a certain parent box! display:flex;, then how to divide it up and down? Continue to add flex-wrap: wrap; which separates the upper and lower parts. Isn’t it very convenient?

  • The next step is the lower part. ul is nested in p, and the height of ul is easy to understand. It is the height of p. So how wide is ul? , can be infinitely wide! ! ! Let's make the width of ul 3000px

  • Let's put li next. As you see, the inside of li also has a top-down structure, so, hehe! Does li also need to enable flex? flex-wrap: wrap;. The p at the top is for img, and the a tag at the bottom.

  • Remember, li needs to float! And consider overflow: hidden put there

animation effect

  • We have five pictures, and we now make them move from right to left. Then we call ul movement, is it possible to drive li movement?

  • We use @keyframes to change the left value of ul, but here comes the problem. I put five pictures and ul moves, and the right side is gone and blank. What to do? ? ?

  • Can we make another copy of the five li and put it at the back? The answer is yes! ! When our left just removes the first group of li, then the second group just doesn't come up. Then we use animation: run 20s linear infinite; is it okay to loop infinitely?

css partial code

* {
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
}

.box-big {
    position: absolute;
    display: flex;
    left: 50%;
    top: 50%;
    border: 1px solid #9FD6FF;
    transform: translate(-50%, -50%);
    width: 707px;
    height: 170px;
    /* background-color: pink; */
    flex-wrap: wrap;
    overflow: hidden;
}

.box-top {
    width: 707px;
    height: 30px;
    border-bottom: 1px solid #9FD6FF;
    background-color: #FEFEFE;
}

.p-bottom {
    width: 707px;
    height: 136px;
    /* background-color: darkgoldenrod; */
    overflow: hidden;
}

.st-icon-android {
    display: inline-block;
    width: 15px;
    height: 15px;
    background-image: url(../img/hd.gif);
    margin: 8px;
}

h5 {
    position: absolute;
    top: 6PX;
    left: 30px;
    color: #307DD1;
}

ul {
    position: absolute;
    left: 90px;
    width: 3000px;
    height: 100%;
    animation: run 20s linear infinite;
}

li {
    list-style: none;
    float: left;
    width: 140px;
    height: 100%;
    margin: 0 5px 0 5px;
    /* background-color: gold; */
    flex-wrap: wrap;
}

.photo {
    margin-top: 5px;
    width: 140px;
    height: 105px;
    text-align: center;
    /* background-color: springgreen; */
}

p {
    text-align: center;
}

img {
    cursor: pointer;
}

@keyframes run {
    0% {
        left: 0;
    }
    100% {
        left: -745px;
    }
}
Copy after login

Recommended tutorial: "CSS Tutorial"

The above is the detailed content of CSS Flex layout for seamless scrolling. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips and methods to achieve seamless scrolling effect with CSS Tips and methods to achieve seamless scrolling effect with CSS Oct 25, 2023 pm 12:31 PM

CSS techniques and methods to achieve seamless scrolling effects require specific code examples. With the development of Internet technology, seamless scrolling effects are widely used in web design. It can bring users a better browsing experience and can also increase the dynamics and visual effects of web pages. In this article, I will introduce several commonly used CSS techniques and methods to achieve seamless scrolling effects, and provide specific code examples. Use CSS Animation to Achieve Seamless Scroll Effect CSS animation is a simple and efficient way to achieve seamless scrolling effect. We can use @key

How to use CSS to create a seamless scrolling text carousel effect How to use CSS to create a seamless scrolling text carousel effect Oct 25, 2023 am 10:24 AM

How to use CSS to create a seamless scrolling text carousel effect requires specific code examples. With the development of the Internet and designers' increasing requirements for user experience, the text carousel effect on websites has become one of the common display forms. Text carousels can attract users' attention, increase the dynamics and vitality of the page, and increase users' attention to the content. In this article, I will introduce you to how to use CSS to create a seamless scrolling text carousel effect, and provide specific code examples. Before creating a seamless scrolling text carousel effect, I

Take you step by step to implement 3D dice using CSS Flex and Grid layout (with code) Take you step by step to implement 3D dice using CSS Flex and Grid layout (with code) Sep 23, 2022 am 09:58 AM

In front-end interviews, we are often asked how to implement dice/mahjong layout using CSS. The following article will introduce to you how to use CSS to create a 3D dice (Flex and Grid layout implement 3D dice). I hope it will be helpful to you!

What are the commonly used Flex layout properties? What are the commonly used Flex layout properties? Feb 25, 2024 am 10:42 AM

What are the common properties of flex layout? Specific code examples are required. Flex layout is a powerful tool for designing responsive web page layouts. It makes it easy to control the arrangement and size of elements in a web page by using a flexible set of properties. In this article, I will introduce the common properties of Flex layout and provide specific code examples. display: Set the display mode of the element to Flex. .container{display:flex;}flex-directi

How to use Vue to achieve seamless scrolling advertising effects How to use Vue to achieve seamless scrolling advertising effects Sep 21, 2023 am 11:24 AM

How to use Vue to implement seamless scrolling advertising effects In modern web design, seamless scrolling advertising effects have become very popular. This special effect can attract users' attention and display multiple advertising contents at the same time. Vue is a popular JavaScript framework that provides a simple and reliable way to achieve this effect. This article will show you how to use Vue to create a seamless scrolling ad effect and provide specific code examples. Step 1: Create a Vue component First, we need to create a Vue component to implement

Methods and techniques for achieving seamless scrolling news through pure CSS Methods and techniques for achieving seamless scrolling news through pure CSS Oct 19, 2023 am 10:46 AM

Methods and techniques on how to achieve seamless scrolling news through pure CSS. With the continuous development of Web technology, how to achieve some cool effects through CSS has become the pursuit of front-end developers. This article will introduce methods and techniques on how to achieve seamless scrolling news through pure CSS, and provide specific code examples. 1. Implementation ideas There are generally two ideas for implementing seamless scrolling news effects: using CSS animation and using the transform attribute of CSS3. Below we will introduce these two methods one by one. 1. Use CSS animation C

An article explaining in detail the impact of three flex properties on elements An article explaining in detail the impact of three flex properties on elements Aug 30, 2022 pm 07:50 PM

During development, the flex attribute is often used to act on the child elements of the flexible box, such as: flex:1 or flex: 1 1 auto. So how does this attribute control the behavior of the element? What exactly does flex:1 mean? Let this article take you through a thorough understanding of the flex property!

Take you through the three attributes of Flex layout: flex-grow, flex-shrink, flex-basis Take you through the three attributes of Flex layout: flex-grow, flex-shrink, flex-basis Dec 06, 2022 pm 08:37 PM

This article will give you an in-depth understanding of the three properties of CSS Flex layout: flex-grow, flex-shrink, and flex-basis. I hope it will be helpful to you!

See all articles