Since its launch in 2009, flex has been supported by almost all browsers. As a simple, responsive layout solution, flex brings a lot of convenience to our layout development. However, during a development, I discovered that space-evenly faces compatibility issues when used. When testing on an iPhone 5s, I found that the child elements in the container with justify-content: space-evenly set were not evenly distributed along the main axis as expected, but were squeezed to the left. .container { display: flex; justify-content: space-evenly; } After checking Can I use space-evenly?, I found that the supported range of space-evenly is indeed relatively small. The definition of the space-evenly property on MDN is: Flex items are evenly distributed along the main axis within the specified alignment container. The spacing between adjacent flex items, the spacing from the start of the main axis to the first flex item, and the spacing from the end of the main axis to the last flex item are all exactly the same. To solve this problem, I thought of two ways: Using flex-grow flex-grow specifies how the remaining space of the container should be distributed to child elements. .container { display: flex; .child: { flex: 1; } } Using space-betweenAnother way is to use space-between which is similar to the space-evenly property. These two properties are very close, and space-between will rarely encounter compatibility issues. The difference is that under space-evenly, each child element has the same space on both sides, while under space-between, the first element of each line is aligned with the beginning of the line, and the last element of each line is aligned with the end of the line. Assuming there are five child elements in a container, the difference between these two attributes can be simply expressed as: // space-evenly |--son--son--son--son--son--| // space-between |Zi--Zi--Zi--Zi--Zi| That is to say, space-evenly will have two more gaps on both sides than space-between, while the first and last child elements of space-between are close to the edge of the container. To fill this gap, we can use two pseudo-elements to allow the container to have seven child elements when set to space-between, which means there are "six gaps": Code: .container { display: flex; justify-content: space-between; &:before, &:after { content: ''; display: block; } } This concludes this article on two methods to solve space-evenly compatibility issues. For more space-evenly compatibility content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. We hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Summary of several implementations of returning to the top in HTML pages
>>: Building an image server with FastDFS under Linux
Overview Today we will mainly share how to config...
To understand load balancing, you must first unde...
1. To optimize the query, try to avoid full table...
1. Preparation Middleware: Tomcat, Redis, Nginx J...
Nginx is developed in C language and is recommend...
The JD carousel was implemented using pure HTML a...
The webpage displays 403 Forbidden Nginx (yum ins...
Pre-installation work: Make sure vmware workstati...
Solution-1: Download the msvcr100.dll file (find ...
Preface I have installed MySQL 5.6 before. Three ...
<br />Previous article: Web Design Tutorial ...
Table of contents Angular accomplish Calling orde...
<br />Hello everyone! It’s my honor to chat ...
This article example shares the specific code of ...
1. Demand The local test domain name is the same ...