当前位置:网站首页>div水平布局两边对齐
div水平布局两边对齐
2022-07-29 09:36:00 【Sabo】
方法一
父容器div使用 position: relative;
,子div使用 position:absolute;
定位,注意边距问题
html
<div class="div-container">
<div class="div1">1</div>
<div class="div2">2</div>
</div>
css
/* 方法一 */
.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;
/* 边距设置 */
right: 10px;
top: 10px;
}
父容器div使用 display:flex; justify-content:space-between;
即可
html
<div class="div-container2">
<div class="div3">3</div>
<div class="div4">4</div>
</div>
css
/* 方法二 */
.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;
}
方法三
父容器div使用display: flex;
实现水平排列, 子div设置宽度进行填充占位
html
<div class="div-container3">
<div class="div5">5</div>
<div class="div7">占位div</div>
<div class="div6">6</div>
</div>
css
/* 方法三 */
.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 完整代码链接 https://github.com/gywgithub/exercise01/blob/master/div-flex/index.html
边栏推荐
- C语言的传参方式(int x)(int *x)(int &x)
- Parameter passing mode of C language (int x) (int *x) (int & x)
- WebAssembly 2022 问卷调查结果新鲜出炉
- 【机器学习】逻辑回归代码练习
- How to introduce your project experience?
- Opencv introductory basic learning
- Unity 引导系统.点击目标物体后提示文字变色进入下一步
- 简述堆和栈的区别
- No swagger, what do I use?
- "Defects" of prototype chain inheritance and constructor inheritance
猜你喜欢
WebAssembly 2022 问卷调查结果新鲜出炉
深入浅出依赖注入及其在抖音直播中的应用
查看端口占用情况
How to query express logistics and filter out no information doc No. to delete or copy
Pyqt5 rapid development and practice 6.4 qboxlayout (box layout)
Pyqt5 rapid development and practice 6.5 qgridlayout (grid layout)
No swagger, what do I use?
不用Swagger,那我用啥?
先序遍历/后序遍历确定树的大致形态
Retinal Vessel Segmentation via a Semantics and Multi-Scale Aggregation Network
随机推荐
MySQL事务与MVCC如何实现的隔离级别
dataframe. to_ Sql() inserts too many errors at one time
基于C语言模拟实现DFA识别字符串
如何介绍自己的项目经验?
[unity entry program] collection of common learning websites
(视频+图文)机器学习入门系列-第1章 引言
RTMP supports h265 streaming
当 update 修改数据与原数据相同时会被更新吗?
【集中培训】HCIP-Cloud Computing 资源交流帖
C # use restsharp library to realize post request
How to realize the isolation level between MySQL transactions and mvcc
23 postgraduate entrance examination people hold on! The first wave of exam abandonment peak has arrived!
Summary of pit trampling records and solutions of data warehouse project
Asp graduation project - based on C # +asp Net+sqlserver laboratory reservation system design and Implementation (graduation thesis + program source code) - Laboratory Reservation System
常用的DOS命令[逐渐完善]
基于C语言实现的NFA确定化和DFA最小化
Study and exploration of Redux API implementation of Redux
Senparc.Weixin.Sample.MP源码剖析
How to introduce your project experience?
Zhongang Mining: four steps for sustainable and healthy development of fluorite industry