常见网页布局
页面布局分析
为了提高网页制作的效率,布局时通常有以下的布局流程:
-
必须确定页面的版心(可视区),我们测量可得知
-
分析页面中的行模块,以及每个行模块中的列模块。其实页面布局,就是一行行罗列而成的
-
制作 HTML
结构。我们还是遵循,先有结构,后有样式的原则。结构永远最重要
-
开始运用盒子模型的原理,通过 div
+ CSS
布局来控制网页的各个模块
初识常见网页布局


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <!doctype html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>常见网页布局</title> <style> * { margin: 0; padding: 0; }
li { list-style: none; }
.top { height: 50px; background-color: gray; }
.banner { width: 980px; height: 150px; background-color: gray; margin: 10px auto; }
.box { width: 980px; margin: 0 auto; height: 300px; background-color: pink; }
.box li { float: left; width: 237px; height: 300px; background-color: gray; margin-right: 10px; }
.box .last { margin-right: 0; }
.footer { height: 200px; background-color: gray; margin-top: 10px; } </style> </head>
<body> <div class="top">top</div> <div class="banner">banner</div> <div class="box"> <ul> <li>1</li> <li>2</li> <li>3</li> <li class="last">4</li> </ul> </div> <div class="footer">footer</div> </body>
</html>
|

完整布局
整体样式

目的
-
熟悉布局(块元素、浮动)
-
公共css部分复用
-
复习语义标签
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <header></header>
<main> <nav></nav> <article> <div class="top"></div> <div class="bottom"> <div class="left"></div> <div class="middle"></div> <div class="right"></div> </div> </article> <aside></aside> </main>
<footer></footer>
|
css代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| header, main, footer { width: 1000px; margin: 10px auto; }
main nav, main article, main aside { float: left; height: 100%; }
.bottom .left, .bottom .middle, .bottom .right { float: left; width: 220px; height: 100%; }
header { height: 100px; background-color: silver; }
main { height: 400px; background-color: #bfa; }
main nav { width: 150px; background-color: red; }
main article { width: 680px; background-color: green; margin: 0 10px; }
article .top { height: 190px; background-color: yellow; margin-bottom: 10px; }
article .bottom { height: 200px; background-color: orange; }
.bottom .left { background-color: lightblue; }
.bottom .middle { background-color: gray; margin: 0 10px; }
.bottom .right { background-color: wheat; }
main aside { width: 150px; background-color: blue; }
footer { height: 100px; background-color: tomato; }
|
效果

浮动
高度塌陷与BFC