Recently, during the development process, I encountered a layout that was aligned at both ends. The layout was based on percentages. I had used flex layout before, but when using flex layout at both ends, all kinds of bugs would occur. For example, when the following is dynamically generated, three or more columns will distribute the following list on both sides. I found some tutorials online, and they all had fixed widths for operations. I changed it into percentage format and recorded it simply. <style> * { padding: 0px; margin: 0px; box-sizing: border-box; } .max-box { max-width: 1200px; margin: 0px auto; } .box { overflow: hidden; width: calc(100% + 20px); margin-left: -10px; } .inner { height: 100px; border: solid 1px red; float: left; margin-left: 10px; width: calc(((100% - 20px) - 10px * 3) / 4); } .max-box2 { max-width: 1200px; margin: 50px auto; border: solid 1px red; height: 200px; } </style> Then on to html <div class="max-box2"> </div> <div class="max-box"> <div class="box"> <div class="inner"> </div> <div class="inner"> </div> <div class="inner"> </div> <div class="inner"> </div> </div> </div> Put these into HTML and you can see the effect. Finally, let’s summarize the formula x = 10px; i.e. the desired spacing y = 4 i.e. the desired number of rows Parent: width: calc(100% + (x * 2)); Child: width: calc(((100% - (x * 2)) - x * ( y - 1)) / y ); Summarize This is the end of this article about CSS layout - two-end layout (using parent's negative margin). For more relevant CSS layout parent's negative margin content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Detailed explanation of Linux netstat command
>>: The concrete implementation of JavaScript exclusive thinking
This article shares with you a detailed tutorial ...
Table of contents Preface Background Implementati...
Requirement: Celery is introduced in Django. When...
I was in a meeting when a colleague called to rep...
Table of contents Million-level data processing s...
In new projects, axios can prevent duplicate subm...
Method 1: Use Google advanced search, for example...
These two attributes are often used, but their di...
I have written such an article before, but I used...
Table of contents 1. Introduction to FastDFS 1. I...
Preface Programming languages usually contain v...
This article shares the specific code of Vue to a...
Table of contents 1. Basic Introduction to JavaSc...
First create a specific project directory for you...
The two parameters innodb_flush_log_at_trx_commit...