两翼齐飞又叫双飞翼布局,是一个三列布局,中间自适应宽度,两翼固定宽度的一种布局模型。
经典布局方案
1三个容器在一排,所以我们可以使用浮动布局
2中间的自适应,我们可以让其占一整行,然后让子元素通过margin居中来自适应
3后面橘黄色的元素,要放在最前面,移动的是绿色元素父容器的宽度,向左平移,所以设置负值
4后面蓝色的元素,要放在最后面,根据浮动贴边特性,只需要向前移动蓝色盒子的宽度即可
简化版(固比固布局) :就是中间自适应,左右固定,所以可以并列三个元素,前面两个脱离文档流(浮动) ,然后一左一右,设置固定宽度即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* .main必须设置 */
/* 注意:这三个是兄弟关系,不是父子关系 */
.main{
height: 500px;
width: 100%;
background-color: gray;
float: left;
}
/* 居中自适应宽度 */
.content{
height: 700px;
margin: 0 400px;
background-color: green;
}
.left{
height: 400px;
width: 300px;
float: left;
background-color: gold;
margin-left: -100%;
}
.right{
height: 400px;
width: 300px;
float: left;
background-color: blue;
margin-left: -300px;
}
.qaq{
width: 100px;
height: 100px;
background-color: red;
margin-top: 410px;
}
</style>
</head>
<body>
<!-- main在中间自适应宽度 -->
<div class="main">
<div class="content"></div>
</div>
<!-- 显示在左侧 -->
<div class="left">
<div class="qaq"></div>
</div>
<!-- 显示咋右侧 -->
<div class="right"></div>
</body>
</html>