在網頁佈局中,之前只考慮了兩列、三列的佈局方式,可是沒有過多的去考慮在兩列、三列布局的狀況下實現某些自適應的狀況;今天遇到這個問題,在這裏mark一下;css
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> </head> <style type="text/css"> .box1{float: left;width: 300px;height: 150px;background: red;} .box2{margin-left: 300px;background: blue;height: 150px;} </style> <body> <div class="box1"></div> <div class="box2"></div> </body> </html>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> </head> <style type="text/css"> .box1{float: left;width: 300px;height: 150px;background: red;} .box2{background: yellow;height: 150px;overflow: auto;} </style> <body> <div class="box1"></div> <div class="box2"></div> </body> </html>
效果:html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> </head> <style type="text/css"> .box{display: table;width: 100%;} .box1{width: 300px;height: 150px;background: red;display: table-cell;} .box2{background: green;height: 150px;display: table-cell;} </style> <body> <div class="box"> <div class="box1"></div> <div class="box2"></div> </div> </body> </html>