提示:要求:两边定宽,中间自适应!
一、flex实现
代码如下(示例):
<!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>双飞翼布局</title>
<style>
*{
margin: 0;
padding: 0;
border: 0;
box-sizing:border-box;
}
.parent {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.left {
width: 100px;
height: 200px;
background-color: red;
}
.center {
height: 200px;
background-color: black;
flex-grow: 1;
}
.right {
width: 100px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="parent">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
二、定位方式实现
代码如下(示例):
<!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>双飞翼布局</title>
<style>
*{
margin: 0;
padding: 0;
border: 0;
box-sizing:border-box;
}
.parent {
width: 100%;
position: relative;
}
.left {
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 200px;
background-color: red;
}
.center {
height: 200px;
background-color: black;
}
.right {
position: absolute;
right: 0;
top: 0;
width: 100px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="parent">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</body>
</html>
三、float实现
注意:使用浮动实现三栏布局效果,布局方式有所变化,中间的盒子需要放在最后面。
代码如下(示例):
<!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>双飞翼布局</title>
<style>
*{
margin: 0;
padding: 0;
border: 0;
box-sizing:border-box;
}
.parent {
width: 100%;
}
.left {
float: left;
width: 100px;
height: 200px;
background-color: red;
}
.center {
height: 200px;
background-color: black;
}
.right {
float: right;
width: 100px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="parent">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>
</body>
</html>