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
I remember a question the interviewer asked durin...
After installing Jenkins, the initial download of...
introduction I discovered a problem before: somet...
1. Install openssh-server yum install -y openssl ...
Promise is a new solution for asynchronous progra...
Table of contents Preface Why does limit deep pag...
This article describes how to add or expand a dis...
This article example shares the specific code of ...
1. Project Documents 2. Use HTML and CSS for page...
As a programmer who has just learned Tomcat, this...
Solution: Directly in the directory where you dow...
1. Clear floating method 1 Set the height of the ...
Table of contents 1. Filter, map, and reduce proc...
Therefore, we made a selection of 30 combinations ...
When we check the source code of many websites, w...