当前位置:网站首页>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
边栏推荐
- Commonly used DOS commands [gradually improved]
- Introduction to translation professional qualification (level) examination
- 【集中培训】HCIP-Cloud Computing 资源交流帖
- RTMP supports h265 streaming
- [machine learning] naive Bayesian code practice
- 不用Swagger,那我用啥?
- I don't know how lucky the boy who randomly typed logs is. There must be a lot of overtime
- Libyuv module
- How to introduce your project experience?
- 基于C语言实现的NFA确定化和DFA最小化
猜你喜欢

Nucleic acid scanning code registration experience (how to improve the correct character recognition rate of OCR)

一知半解 ~题目杂记 ~ 一个多态问题

Custom configuration

【BERT-多标签文本分类实战】之一——实战项目总览

On contract testing

How to introduce your project experience?

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

Unity Xchart3.0基本用法快速上手

23考研人撑住!考研第一波弃考高峰期已经到来!

【机器学习】朴素贝叶斯代码练习
随机推荐
怎样查询快递物流筛选出无信息单号删除或者复制
OpenCV图像处理基础操作
存算一体与存内计算计算杂谈
Zhongang Mining: four steps for sustainable and healthy development of fluorite industry
数仓项目踩坑记录与解决方法总结
Configuration file settings for remote connection to Windows version server redis
当 update 修改数据与原数据相同时会被更新吗?
Visual Studio
Network security (5)
Commonly used DOS commands [gradually improved]
Redis command [gradually improved]
Discussion on the integration of storage and calculation and the calculation in storage
【机器学习】逻辑回归代码练习
怎么样的框架对于开发者是友好的?
Opencv introductory basic learning
dataframe.to_sql() 一次性插入过多报错
pytest+allure生成测试报告
vector实现
[苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题
23考研人撑住!考研第一波弃考高峰期已经到来!