左右两边固定,中间自适应的布局方式(圣杯布局)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
height: 200px;
background-color: pink;
display: flex;
text-align: center;
}
.left {
width: 200px;
order: 1;
background-color: purple;
}
.center {
flex: 1;
order: 2;
}
.right {
width: 200px;
order: 3;
background-color: skyblue;
}
</style>
</head>
<body>
<div class="box">
<div class="center">中间</div>
<div class="left">左侧</div>
<div class="right">右侧</div>
</div>
</body>
</html>
运行结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/eafb2dc6f8cac2e01550ce9a45bac06e.png)