常见网页布局

页面布局分析

为了提高网页制作的效率,布局时通常有以下的布局流程:

  1. 必须确定页面的版心(可视区),我们测量可得知

  2. 分析页面中的行模块,以及每个行模块中的列模块。其实页面布局,就是一行行罗列而成的

  3. 制作 HTML 结构。我们还是遵循,先有结构,后有样式的原则。结构永远最重要

  4. 开始运用盒子模型的原理,通过 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>

完整布局

整体样式

image-20220725222522959

目的

  1. 熟悉布局(块元素、浮动)

  2. 公共css部分复用

  3. 复习语义标签

代码

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;
}

效果

image-20220725222543224

浮动 高度塌陷与BFC