当前位置:网站首页>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
边栏推荐
- Summary of pit trampling records and solutions of data warehouse project
- AxureRP原型设计 快速开始
- 网络安全(6)
- In simple terms, dependency injection and its application in Tiktok live broadcast
- 使用cpolar发布树莓派网页(cpolar隧道的完善)
- 系统架构师学习
- 引入redis缓存出现的问题以及解决方式
- Parameter passing mode of C language (int x) (int *x) (int & x)
- 40余岁的边缘老技术,是未来乏力还是掘地而起?
- 不用Swagger,那我用啥?
猜你喜欢

Use cpolar to publish raspberry pie web pages (improvement of cpolar tunnel)

vector实现

(Video + graphics) introduction to machine learning series - Chapter 1 Introduction

How to introduce your project experience?

乱打日志的男孩运气怎么样我不知道,加班肯定很多

【C语言】扫雷(递归展开 + 标记功能)

STM32 application development practice tutorial: design and implementation of controllable LED water lamp

PyQt5快速开发与实战 6.5 QGridLayout(网格布局)

Pyqt5 rapid development and practice 6.1 three dimensions of good software & 6.2 layout management in pyqt5 & 6.3 absolute location layout of pyqt5

Gao Zhiwei: data management enables the digital transformation of the transportation industry
随机推荐
Webassembly 2022 questionnaire results are fresh
How to choose effective keywords
Redis command [gradually improved]
数据库表结构生成excel工具
Evaluation index of machine learning classification model and implementation of sklearn code
Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages
高智伟:数据管理赋能交通行业数字化转型
How to change MySQL into Chinese
Shutter gradient
Will the modified data be updated when it is the same as the original data?
Unity 引导系统.点击目标物体后提示文字变色进入下一步
What kind of framework is friendly to developers?
用户身份标识与账号体系实践
【云驻共创】【HCSD大咖直播】亲授大厂面试秘诀
如何介绍自己的项目经验?
Implementation of DFA string recognition based on C language simulation
Vs2015 uses loadlibrary to call DLL library
Acwing game 59 [End]
Pyqt5 rapid development and practice 6.5 qgridlayout (grid layout)
First order traversal / second order traversal determines the approximate shape of the tree