<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> \* { padding: 0; margin: 0; } .container { padding-left: 200px; padding-right: 200px; } .left { float: left; width: 200px; height: 400px; background: red; margin-left: -100%; position: relative; left: -200px; } .center { float: left; width: 100%; height: 400px; background: yellow; } .right { float: left; width: 200px; height: 400px; background: blue; margin-left: -200px; position: relative; right: -200px; } </style> </head> <body> <section class="container"> <div class="center"></div> <div class="left"></div> <div class="right"></div> </section> </body> </html>
步骤
先写center
部分,width 100%
html
center
,left
,right
都是左浮动dom
父容器container
设置padding-left
和padding-right
布局
设置margin-left
为负值让left
和right
部分回到与center
部分同一行ui
设置相对定位,让left
和right
部分移动到两边spa
center部分的最小宽度不能小于left部分的宽度scala
其中一列内容高度拉长,其余两列的高度不会自动填充code
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> \*{ padding: 0; margin: 0; } .container { min-width: 600px; } .left { float: left; width: 200px; height: 400px; background: red; margin-left: -100%; } .center { float: left; width: 100%; height: 400px; background: yellow; } .center .inner { margin: 0 200px; } .right { float: left; width: 200px; height: 400px; background: blue; margin-left: -200px; } </style> </head> <body> <section class="container"> <div class="center"> <div class="inner">双飞翼布局</div> </div> <div class="left"></div> <div class="right"></div> </section> </body> </html>
先写center
部分,width 100%
htm
center
,left
,right
都是左浮动图片
center
部分增长一个内层div
,并设margin-left
,margin-right
it
设置margin-left
为负值让left
和right
部分回到与center
部分同一行
多加一层 dom
树节点