首页 > 作文

div水平布局两边对齐的三种实现方法

更新时间:2023-04-07 17:31:36 阅读: 评论:0

本文主要介绍了div水平布局两边对齐的三种实现方法,分享给大家,具体如下:

方法一

父容器div使用 position: relative;,子div使用 position:absolute;定位,注意边距问题

html

<div class="div-container">  <div cla上海戏剧学院校花ss="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; hcl是什么 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 完整代码链接

到此这篇关于div水平布局两边对齐的三种老虎拉车实现方法的文章就介绍到这了,更多相关div水平布局两边对齐内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章,希望大家以后多多支持www.887551.com!

本文发布于:2023-04-07 17:31:35,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/d21689ed44a78d10b93e19840b45dc8a.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:div水平布局两边对齐的三种实现方法.doc

本文 PDF 下载地址:div水平布局两边对齐的三种实现方法.pdf

下一篇:返回列表
标签:方法   水平   容器   布局
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图