左右定宽中间自适应有三种实现方法:
1.flex伸缩盒布局
2.绝对定位
3.float浮动布局(注意用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>Document</title>
<style>
/* 第一种:flex伸缩盒布局 */
body {
display: flex;
}
.first {
width: 100px;
height: 100%;
background-color: pink;
}
.second {
background-color: blue;
flex: 1;
}
.third {
width: 100px;
height: 100%;
background-color: red;
}
/* 第二种:相对定位 */
body {
margin: 0;
padding: 0;
}
.first {
width: 300px;
height: 200px;
position: absolute;
top: 0;
left: 0;
background-color: pink;
}
.second {
margin: 0 300px;
height: 200px;
background-color: blue;
}
.third {
width: 300px;
height: 200px;
position: absolute;
top: 0;
right: 0;
background-color: red;
}
/* 第三种:float浮动 */
body {
margin: 0;
padding: 0;
}
.first {
width: 300px;
height: 200px;
float: left;
background-color: pink;
}
.second {
width: 300px;
height: 200px;
float: right;
background-color: red;
}
/*注意用float盒子一定要是左右中顺序*/
.third {
margin-left: 300px;
margin-right: 300px;
height: 200px;
background-color: blue;
}
</style>
</head>
<body>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</body>
</html>