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

Research on the effect of page sidebar realized by JS

Table of contents Discover: Application of displa...

How to quickly insert 10 million records into MySQL

I heard that there is an interview question: How ...

Unicode signature BOM (Byte Order Mark) issue for UTF-8 files

I recently encountered a strange thing when debug...

Detailed explanation of Nodejs array queue and forEach application

This article mainly records the problems and solu...

A practical record of troubleshooting a surge in Redis connections in Docker

On Saturday, the redis server on the production s...

Detailed explanation of how to detect and prevent JavaScript infinite loops

Table of contents Preface Fix infinite loop in fo...

Key issues and solutions for web page access speed

<br /> The website access speed can directly...

MySQL 8.0.18 installation and configuration method graphic tutorial (linux)

This article records the installation and configu...

How to use JS to parse the excel content in the clipboard

Table of contents Preface 1. Paste Events and Cli...

JavaScript custom plug-in to implement tab switching function

This article shares the specific code of JavaScri...

How to view MySQL links and kill abnormal links

Preface: During database operation and maintenanc...

WeChat applet realizes multi-line text scrolling effect

This article example shares the specific code for...