当前位置:网站首页>Div horizontal layout aligned on both sides
Div horizontal layout aligned on both sides
2022-07-29 09:37:00 【Sabo】
Method 1
Parent container div Use position: relative;, Son div Use position:absolute; location , Pay attention to the margin
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 setting */
right: 10px;
top: 10px;
} Parent container div Use display:flex; justify-content:space-between; that will do
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 3
Parent container div Use display: flex; Achieve horizontal arrangement , Son div Set 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
边栏推荐
- AxureRP原型设计 快速开始
- Acwing game 59 [End]
- C # use restsharp library to realize post request
- 如何为OpenHarmony做贡献
- Sublime Text3 设置不同文件不同缩进
- Source code analysis of senparc.weixin.sample.mp
- Quick sorting (quick sorting) (implemented in C language)
- Unity3d hodgepodge
- C# 使用RestSharp库实现POST请求
- In simple terms, dependency injection and its application in Tiktok live broadcast
猜你喜欢

36. JS动画

Outlook tutorial, how to create an electronic signature in outlook?

Gao Zhiwei: data management enables the digital transformation of the transportation industry

How to change MySQL into Chinese
![[machine learning] naive Bayesian code practice](/img/42/38e8cfa8ebfbb0e14c2e26ffc6c793.png)
[machine learning] naive Bayesian code practice

View port occupancy
![[machine learning] logistic regression code exercise](/img/dc/203f240e2eb213dbd6173d17e47ec6.jpg)
[machine learning] logistic regression code exercise

如何介绍自己的项目经验?

Senparc.Weixin.Sample.MP源码剖析

Use cpolar to publish raspberry pie web pages (improvement of cpolar tunnel)
随机推荐
System architect learning
First order traversal / second order traversal determines the approximate shape of the tree
开放原子开源基金会黄金捐赠人优博讯携手合作伙伴,助力OpenHarmony破圈!
Pytest+allure generate test report
redis命令[逐渐完善]
40余岁的边缘老技术,是未来乏力还是掘地而起?
Nucleic acid scanning code registration experience (how to improve the correct character recognition rate of OCR)
MySQL事务与MVCC如何实现的隔离级别
数据库表结构生成excel工具
Handwritten character recognition
Flutter文本编辑器
一知半解 ~题目杂记 ~ 一个多态问题
Unity 引导系统.点击目标物体后提示文字变色进入下一步
Shutter gradient
Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages
36. JS animation
C# 使用RestSharp库实现POST请求
Solve the problem of reading data garbled by redis visualization tool
【集中培训】HCIP-Cloud Computing 资源交流帖
[Yunzhu co creation] [hcsd live broadcast] teach the interview tips of big companies in person