This article mainly introduces three methods of implementing the alignment of div horizontal layout on both sides, and shares them with you, as follows: Method 1The parent container div uses position: relative;, and the child div uses position: absolute; to position, pay attention to the margin problem html <div class="div-container"> <div class="div1">1</div> <div class="div2">2</div> </div> CSS /* Method 1 */ .div-container { margin: 10px 0; padding: 10px; width: 400px; border: 2px solid #ccc; position: relative; } .div1 { width: 100px; height: 50px; border: 2px solid red; } .div2 { width: 100px; height: 50px; border: 2px solid red; position: absolute; /* Margin settings */ right: 10px; top: 10px; } Method 2 RecommendedThe parent container div uses display:flex; justify-content:space-between; html <div class="div-container2"> <div class="div3">3</div> <div class="div4">4</div> </div> CSS /* Method 2 */ .div-container2 { margin: 10px 0; padding: 10px; width: 400px; border: 2px solid #ccc; display: flex; justify-content: space-between; } .div3 { width: 100px; height: 50px; border: 2px solid red; } .div4 { width: 100px; height: 50px; border: 2px solid red; } Method 3The parent container div uses display: flex; to achieve horizontal arrangement, and the child div sets the width to fill the space. html <div class="div-container3"> <div class="div5">5</div> <div class="div7">Placeholder div</div> <div class="div6">6</div> </div> CSS /* Method 3 */ .div-container3 { margin: 10px 0; padding: 10px; width: 400px; border: 2px solid #ccc; display: flex; justify-content: space-between; } .div5 { width: 100px; height: 50px; border: 2px solid red; } .div6 { width: 100px; height: 50px; border: 2px solid red; } .div7 { width: calc(100% - 100px - 100px); height: 50px; border: 1px solid #ccc; } GitHub full code link https://github.com/gywgithub/exercise01/blob/master/div-flex/index.html This concludes this article on three ways to achieve horizontal alignment of div layouts. For more information on horizontal alignment of div layouts, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Detailed explanation of meta tags and usage in html
>>: Introduction to building a DNS server under centos7
Table of contents 1. Prototype Relationship 2. Pr...
Many times when we process file uploads, such as ...
Table of contents 1. Array Induction 1. Split a s...
Table of contents The pitfalls Filling method Wha...
This article shares the MySQL 5.7.18 MSI installa...
1. Add skip-grant-tables to the my.ini file and r...
This article shares the specific code for JavaScr...
Table of contents 1. In project development, the ...
If your MySQL database is installed on a centos7 ...
The requirements are as follows: There are multip...
Table of contents Row-Column Conversion Analyze t...
The Linux stream editor is a useful way to run sc...
1. Environment: MySQL-5.0.41-win32 Windows XP Pro...
Optimize the fastcgi configuration file fcgiext.i...
Table of contents 1. Achieve results 2. Implement...