Detailed explanation of two methods to solve a bug in the justify-content: space-between alignment of flex layout

Detailed explanation of two methods to solve a bug in the justify-content: space-between alignment of flex layout

When setting display:flex, justify-content: space-betweend, it will align the child elements to the sides and evenly divide the remaining space.

For example: if you want to put three child elements in one row

Effect:

This seems to be fine and looks good, but if there are not three characters in the next row, there will be problems if there are only two.

This looks particularly disgusting, with a large empty space in the middle. It looks particularly like a bug, rather than the desired effect of aligning one by one with the previous line.

Now to solve this problem, here are two methods:

  • Pseudo-class: after
  • Provide a placeholder element

Pseudo-class solution

Placeholder element solution

Effect

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.

<<:  Web designer is a suitable talent

>>:  Usage instructions for the docker create command

Recommend

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...

Detailed usage of kubernetes object Volume

Overview Volume is the abstraction and virtualiza...

MySQL 5.7.18 winx64 installation and configuration method graphic tutorial

The installation of compressed packages has chang...

7 skills that web designers must have

Web design is both a science and an art. Web desi...

Solution to no Chinese input method in Ubuntu

There is no solution for Chinese input method und...

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...

Ubuntu starts the SSH service remote login operation

ssh-secure shell, provides secure remote login. W...

JavaScript common statements loop, judgment, string to number

Table of contents 1. switch 2. While Loop 3. Do/W...

Vue data responsiveness summary

Before talking about data responsiveness, we need...

Simple principles for web page layout design

This article summarizes some simple principles of...

Perfect solution for JavaScript front-end timeout asynchronous operation

Table of contents What happens if a piece of code...

Solution to the img tag problem below IE10

Find the problem I wrote a simple demo before, bu...

MySql multi-condition query statement with OR keyword

The previous article introduced the MySql multi-c...

MySql implements page query function

First of all, we need to make it clear why we use...