摘要:回顾复习页面布局三栏布局左右固定中间自适应部分同一如下中间自适应方法一原理利用第一和第二个盒子的左右浮动,使得与第三个盒子在一行缺点当宽度小于时,会繁发生换行以及中间高度大于时,会有两边覆盖其实中间的宽度就是可以利用解决方法二原理利用绝对定
回顾复习css页面布局 三栏布局
左右固定中间自适应:
html部分同一如下
</>复制代码
中间自适应
style方法一:
</>复制代码
div {
height: 300px;
}
.box1 {
float: left;
width: 300px;
background: red;
}
.box2 {
float: right;
width: 300px;
background: blue;
}
.box3 {
background: yellow;
}
原理:利用第一和第二个盒子的左右浮动,使得与第三个盒子在一行
缺点:当宽度小于600px时,会繁发生换行;以及中间高度大于300px时,会有两边覆盖(其实中间的div宽度就是width:100%;可以利用overflow: hidden解决)
style方法二:
</>复制代码
div {
height: 300px;
}
.box1 {
width: 300px;
background: red;
position: absolute;
left: 0;
}
.box2 {
position: absolute;
right: 0;
width: 300px;
background: blue;
}
.box3 {
background: yellow;
height: 500px;
position: absolute;
left: 300px;
right: 300px;
}
原理:利用绝对定位,来实现left=300px; right=300px
优点:当中间自适应的高度大于两边时不会发生重叠;但是当视窗大小小于600px时,中间会发生重叠,不换行
style方法三:
</>复制代码
中间自适应
原理:外部flex布局;中间利用flex: 1;即flex-basis: 0宽度中间取其容器最大
优点:自适应强,宽度小于600时,会缩小两边宽度;
缺点:低版本浏览器对flex兼容性不好;
style方法四:
</>复制代码
.wrap {
display: table;
width: 100%;
}
.box {
height: 300px;
display: table-cell;
}
.box1 {
width: 300px;
background: red;
}
.box2 {
width: 300px;
background: blue;
}
.box3 {
background: yellow;
height: 300px;
}
原理:利用table布局,来达到自使用,外部divwidth:100%,不然无法填充
优点:自适应强
缺点:中间高度改变会影响两边
style方法五:
</>复制代码
.wrap {
display: grid;
width: 100%;
grid-template-rows: 100px;
grid-template-columns: 300px auto 300px;
}
.box1 {
background: red;
}
.box2 {
background: yellow;
}
.box3 {
background: blue;
}
原理:利用网格布局
优点:编写简单,自适应较强
同理上面的·方法:
方法一 网格布局:
</>复制代码
.wrap {
display: grid;
grid-template-rows: 100px;
grid-template-columns: 100px auto
}
.box1 {
background: red;
}
.box2 {
background: yellow;
}
.box3 {
background: blue;
/* height: 500px; */
}
方法二table布局
</>复制代码
.wrap {
display: table;
width: 100%;
}
.box {
display: table-cell
}
.box1 {
width: 100px;
background: red;
}
.box2 {
background: blue;
}
方法三flex布局
</>复制代码
.wrap {
display: flex;
}
.box1 {
width: 100px;
background: red;
}
.box2 {
background: blue;
flex: 1;
}
方法四绝对定位
</>复制代码
.box1 {
width: 300px;
position: absolute;
left: 0;
background: red;
height: 100px;
}
.box2 {
background: blue;
position: absolute;
left: 300px;
right: 0;
}
方法五浮动布局:
</>复制代码
.box1 {
width: 300px;
float: left;
background: red;
height: 100px;
}
.box2 {
background: blue;
/* overflow: hidden; */
}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/99572.html
摘要:常用布局在小程序中的应用所有布局的根本都是个基本概念定位浮动外边距操纵我们其他的布局实现方式,都是基于正常的文档流来进行的。具体实现,可以使用微信小程序的单位,以及使用定位浮动布局来实现。 CSS 常用布局在小程序中的应用 所有css布局的根本都是3个基本概念:定位、浮动、外边距操纵 我们其他的布局实现方式,都是基于正常的文档流来进行的。所以我们先来看看什么是正常的文档流。 正常文...
摘要:常用布局在小程序中的应用所有布局的根本都是个基本概念定位浮动外边距操纵我们其他的布局实现方式,都是基于正常的文档流来进行的。具体实现,可以使用微信小程序的单位,以及使用定位浮动布局来实现。 CSS 常用布局在小程序中的应用 所有css布局的根本都是3个基本概念:定位、浮动、外边距操纵 我们其他的布局实现方式,都是基于正常的文档流来进行的。所以我们先来看看什么是正常的文档流。 正常文...
阅读 843·2021-11-22 13:54
阅读 3208·2021-09-26 10:16
阅读 3647·2021-09-08 09:35
阅读 1657·2019-08-30 15:55
阅读 3503·2019-08-30 15:54
阅读 2156·2019-08-30 10:57
阅读 561·2019-08-29 16:25
阅读 947·2019-08-29 16:15