这里推荐一个我个人比较喜欢的圣杯布局,即当总宽度收缩时,左右两边优先收缩,最后收缩中间部分。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin:0;
padding:0;
}
.wrap{
display:flex;
flex-direction:row;
margin-top:20px;
}
.center{
width:800px;
text-align:center;
background:#ccc;
}
.left,.right{
/*flex-grow 属性用于设置或检索弹性盒的扩展比率。*/
flex-grow: 1;
line-height: 30px;
background:red;
}
</style>
</head>
<body>
<div class="wrap">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
</body>
</html>