代码:
<!DOCTYPE html>
<html>
<head>
<style>
#container {
margin: 90px;
width: 100%;
}
.header {
background-color: green;
width: 100%;
}
#content {
display: flex;
}
.left {
background: yellow;
width: 20%;
}
.middle {
background: blue;
overflow: hidden;
flex: 1;
}
.right {
background: red;
width: 180px;
}
.footer {
background: brown;
width: 100%;
}
</style>
</head>
<body id="container">
<div class="header">header</div>
<div id="content">
<div class="left">left</div>
<div class="middle">middle</div>
<div class="right">right</div>
</div>
<div class="footer">footer</div>
</body>
</html>
效果:
更加方便,且letf、middle、right位置在html中不用改变。
子元素不用设置float,设置了也不会出错,但是没有必要。
参考
阮一峰 flex : http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html