Example code for implementing card waterfall layout with css3 column

Example code for implementing card waterfall layout with css3 column

This article introduces the sample code of CSS3 column to realize the card waterfall layout, which is shared with you as follows:

Achieve results

Today I encountered the problem of implementing a waterfall layout of cards, and the heights of the cards were different.

Finally, I used the column attribute in CSS3 to implement this layout, and it was very simple (I vaguely remember that the last time I wrote the waterfall flow, I used JS to implement it... naive)

The effect is as follows:

Related properties

  1. column-count: the number of columns you want to achieve, I only need 2 columns here
  2. column-width: The width of the column
  3. column-gap: The gap between columns
  4. break-inside:avoid: If you do not set this attribute for the child elements (each card), a card will be truncated and displayed in different columns.

Problems encountered

  1. I encountered a small problem during the implementation process. The bottom border of my card would be cut off.
  2. Solved by setting overflow:auto on child elements

Code

       .videoCards {
            padding-top: 4rpx;
            column-count: 2;
            column-gap: 18rpx;

            .card {
                display: inline-block;
                margin-top: 20rpx;
                width: 326rpx;
                background: #FFFFFF;
                box-shadow: 0 0 10rpx 0 rgba(0,0,0,0.10);
                border-radius: 14rpx;
                break-inside: avoid;
                padding-bottom: 20rpx;
                overflow:auto;
                }
        }

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to use domestic image warehouse for Docker

>>:  Learn Hyperlink A Tag

Recommend

HTML meta viewport attribute description

What is a Viewport Mobile browsers place web page...

Research on Web Page Size

<br />According to statistics, the average s...

How to install ELK in Docker and implement JSON format log analysis

What is ELK? ELK is a complete set of log collect...

JS realizes the card dealing animation

This article example shares the specific code of ...

How to implement Docker to dynamically pass parameters to Springboot projects

background Recently, some friends who are new to ...

Native JS realizes the special effect of spreading love by mouse sliding

This article shares with you a js special effect ...

Detailed explanation of Alibaba Cloud security rule configuration

Two days ago, I took advantage of the Double 11 s...

Steps to deploy multiple tomcat services using DockerFile on Docker container

1. [admin@JD ~]$ cd opt #Enter opt in the root di...

An example of how JavaScript can prevent duplicate network requests

Preface During development, we often encounter va...

Solve the problem that Navicat cannot connect to MySQL on the Linux server

At the beginning, I felt sad. The screenshots are...

Practice of el-cascader cascade selector in elementui

Table of contents 1. Effect 2. Main code 1. Effec...

How to implement one-click deployment of nfs in linux

Server Information Management server: m01 172.16....

Detailed description of component-based front-end development process

Background <br />Students who work on the fr...

What command is better for fuzzy searching files in Linux?

1. Introduction This article mainly explains how ...