当前位置:网站首页>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语言实现的NFA确定化和DFA最小化
- Summary of research on endogenous information security technology of industrial measurement and control equipment
- MySQL converts some table names to uppercase
- Briefly describe the difference between heap and stack
- Opencv introductory basic learning
- 【C语言】扫雷(递归展开 + 标记功能)
- Unity xchart3.0 basic usage quick start
- HarmonyOS 3.0 发布!
- Axurerp prototype design starts quickly
猜你喜欢

Floweable foundation Chapter 1

In simple terms, dependency injection and its application in Tiktok live broadcast

OpenCV图像处理基础操作

VS2015采用loadlibrary方式调用dll库

Asp graduation project - based on C # +asp Design and implementation of enterprise investment value analysis system based on. Net + sqlserver (graduation thesis + program source code) -- enterprise in

Introduction to translation professional qualification (level) examination

《UnityShader入门精要》总结(2):初级篇

redis可视化工具读取数据乱码问题解决

远程连接windows版本服务器redis的配置文件设置
![[苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题](/img/a7/12fd63f16ebca81a3dd2d1b97847d1.png)
[苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题
随机推荐
[unity entry program] collection of common learning websites
23 postgraduate entrance examination people hold on! The first wave of exam abandonment peak has arrived!
Parameter initialization
In simple terms, dependency injection and its application in Tiktok live broadcast
Flowable UI production flow chart
What kind of framework is friendly to developers?
【机器学习】朴素贝叶斯代码练习
Vs2015 uses loadlibrary to call DLL library
附录2-一些简单的练习
Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
40余岁的边缘老技术,是未来乏力还是掘地而起?
mysql将部分表名统一转换为大写
Flowable UI制作流程图
Solve the problem of reading data garbled by redis visualization tool
Briefly describe the difference between heap and stack
【集中培训】HCIP-Cloud Computing 资源交流帖
Nutnews developed based on arkui ETS
201803-3 Full Score solution of CCF URL mapping
Use cpolar to publish raspberry pie web pages (improvement of cpolar function)
Qmainwindow details