Implementation idea of ​​left alignment of the last row of flex box layout

Implementation idea of ​​left alignment of the last row of flex box layout

Using flex layout, if it is a nine-square grid, it can be divided equally, as shown in the figure

insert image description here

If we only need eight pieces, as shown in the figure

insert image description here

But if we want the last block to be left-aligned and arranged in sequence, we need to add a pseudo-element after to the parent of the element, as shown in the figure

<div class="box">
	<ul>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ul>
</div>
ul{
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
}
ul:after{
	content: "";
	width: 32%;
}
ul li{
	width: 32%;
	height: 10vh;
	margin-bottom: 1vh;
	background: #2fbaff;
} 

insert image description here

This concludes this article about how to implement left-alignment of the last line in flex box layout. For more flex layout content, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  SQL implementation LeetCode (176. Second highest salary)

>>:  Vue implements simple calculator function

Recommend

Basic installation process of mysql5.7.19 under winx64 (details)

1. Download https://dev.mysql.com/downloads/mysql...

MySQL 8.0.12 installation and configuration method graphic tutorial

Record the installation and configuration method ...

How to use resident nodes for layer management in CocosCreator

CocosCreator version: 2.3.4 Most games have layer...

UCenter Home site adds statistics code

UCenter Home is an SNS website building system rel...

nginx solves the problem of slow image display and incomplete download

Written in front Recently, a reader told me that ...

Vue uses three methods to refresh the page

When we are writing projects, we often encounter ...

Implementation methods of common CSS3 animations

1. What is CSS Animations is a proposed module fo...

JavaScript implements bidirectional linked list process analysis

Table of contents 1. What is a doubly linked list...

Detailed explanation of mysql user variables and set statement examples

Table of contents 1 Introduction to user variable...

jQuery realizes the full function of shopping cart

This article shares the specific code of jQuery t...

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

How to use module fs file system in Nodejs

Table of contents Overview File Descriptors Synch...

MySQL 8.0.15 version installation tutorial connect to Navicat.list

The pitfalls 1. Many tutorials on the Internet wr...

Native js implements a minesweeper game with custom difficulty

This article example shares the specific code of ...