当前位置:网站首页>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
边栏推荐
- [Yunzhu co creation] [hcsd live broadcast] teach the interview tips of big companies in person
- View port occupancy
- Parameter passing mode of C language (int x) (int *x) (int & x)
- PyQt5快速开发与实战 6.5 QGridLayout(网格布局)
- Unity Xchart3.0基本用法快速上手
- Implementation of DFA string recognition based on C language simulation
- Quick sorting (quick sorting) (implemented in C language)
- 【C语言】扫雷(递归展开 + 标记功能)
- 数据库表结构生成excel工具
- Unity3d hodgepodge
猜你喜欢

How to introduce your project experience?

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

PyQt5快速开发与实战 6.4 QBoxLayout(框布局)

Vs2015 uses loadlibrary to call DLL library

Qmainwindow details
![[machine learning] logistic regression code exercise](/img/dc/203f240e2eb213dbd6173d17e47ec6.jpg)
[machine learning] logistic regression code exercise

Evaluation index of machine learning classification model and implementation of sklearn code

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

PyQt5快速开发与实战 6.1 好软件的三个维度 && 6.2 PyQt5中的布局管理 && 6.3 PyQt5的绝对位置布局

Appendix 2 – some simple exercises
随机推荐
redis可视化工具读取数据乱码问题解决
数据库表结构生成excel工具
Discussion on the integration of storage and calculation and the calculation in storage
基于C语言实现的NFA确定化和DFA最小化
QoS服务质量五QoS边界行为之流量整形
Unity guidance system. Click the target object and prompt the text to change color to enter the next step
The use and Simulation of string function, character function and memory function
Outlook tutorial, how to create an electronic signature in outlook?
怎么样的框架对于开发者是友好的?
【C语言】扫雷(递归展开 + 标记功能)
Axurerp prototype design starts quickly
(视频+图文)机器学习入门系列-第1章 引言
Gao Zhiwei: data management enables the digital transformation of the transportation industry
redis命令[逐渐完善]
浅谈契约测试
[苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题
23考研人撑住!考研第一波弃考高峰期已经到来!
201803-3 Full Score solution of CCF URL mapping
OpenCV图像处理基础操作
怎样查询快递物流筛选出无信息单号删除或者复制