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
Environment: (docker, k8s cluster), continue with...
The equal height layout described in this article...
123WORDPRESS.COM provides you with the FileZilla ...
Table of contents Build a Docker image using Dock...
The commonly used escape characters in HTML are s...
When insert into employee values(null,'張三'...
Table of contents 1. Basic knowledge of indexing ...
An at-rule is a declaration that provides instruc...
Table of contents accomplish: Summarize: Not much...
Table of contents 1. Introduction to pid-file 2.S...
1. View the current host name [root@fangjian ~]# ...
Table of contents Index Type Index structure Nonc...
View container logs First, use docker run -it --r...
1 Check whether the kernel has a tun module modin...
Mysql8.0.12 decompression version installation me...