代碼:
<!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