1. HTML

1.1 HTML-标题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的联通</title>
</head>
<body>
<h1>1级标题</h1>
<h2>2级标题</h2>
<h3>3级标题</h3>
<h4>4级标题</h4>
<h5>5级标题</h5>
<h6>6级标题</h6>
</body>
</html>
效果图

1.2 HTML-div和span

  • div,一个人占一整行。【块级标签】
  • span,自己多大占多少。【行内标签、内联标签】
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的联通</title>
</head>
<body>
<div>山东蓝翔</div>
<div>挖掘机哪家强</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的联通</title>
</head>
<body>
<span>山东蓝翔</span>
<span>挖掘机哪家强</span>
</body>
</html>

1.3 HTML-超链接

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 1. 跳转到其他网站 -->
<a href="http://www.chinaunicom.com.cn/about/about.html">点击跳转</a>

<!-- 2. 跳转到自己网站其他的地址 -->
<a href="http://127.0.0.1:5000/get/news">点击跳转</a>

<a href="/get/news">点击跳转</a>

<!-- 3. 当前页面打开 -->
<a href="/get/news">点击跳转</a>

<!-- 4. 新的Tab页面打开 -->
<a href="/get/news" target="_blank">点击跳转</a>

1.4 HTML-图片

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 1. 直接显示别人的图片地址(防盗链): -->
<img src="图片地址" />
<img src="https://pic4.zhimg.com/v2-b23f984c2aeaa7bed12e890b4338d499_720w.jpg" />

<!-- 2. 显示自己的图片:
- 自己项目中创建:static目录,图片要放在static
- 在页面上引入图片 -->
<img src="自己图片的地址" />
<img src="/static/wbq.png" />

<!-- 3. 关于设置图片的高度和宽度 -->
<img src="图片地址" style="height:100px; width:200px;" />
<img src="图片地址" style="height:10%; width:20%;" />

1.5 HTML-小结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 块级标签
<h1></h1>
<div></div>
- 行内标签
<span></span>
<a></a>
<img />
- 嵌套
<div>
<span>xxx</span>
<img />
<a></a>
<!-- 点击图片跳转指定地址 -->
<a><img src="自己图片的地址" /></a>
</div>

1.6 HTML-表格和列表

1.6.1 列表

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 1. 无序列表 -->
<ul>
<li>中国移动</li>
<li>中国联通</li>
<li>中国电信</li>
</ul>

<!-- 2. 有序列表 -->
<ol>
<li>中国移动</li>
<li>中国联通</li>
<li>中国电信</li>
</ol>
效果图

1.6.2 表格

1
2
3
4
5
6
7
8
9
10
11
12
<table>
<thead> <!-- 表头 -->
<tr> <th>ID</th> <th>姓名</th> <th>年龄</th> </tr>
</thead>
<tbody> <!-- 表内容 -->
<tr> <td>10</td> <td>武沛齐</td> <td>19</td> </tr>
<tr> <td>11</td> <td>吴阳军</td> <td>19</td> </tr>
<tr> <td>12</td> <td>刘东</td> <td>19</td> </tr>
<tr> <td>13</td> <td>郭智</td> <td>19</td> </tr>
<tr> <td>14</td> <td>电摩</td> <td>19</td> </tr>
</tbody>
</table>
效果图

1.7 HTML-表单标签

1.7.1 input系列(7个)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<input type="text" />
<input type="password">
<!-- 上传文件 -->
<input type="file">

<!-- 单选框 -->
<input type="radio" name="n1">
<input type="radio" name="n1">

<!-- 多选框 -->
<input type="checkbox">篮球
<input type="checkbox">足球
<input type="checkbox">乒乓球
<input type="checkbox">棒球

<!-- 按钮 -->
<input type="button" value="提交"> -->普通的按钮
<input type="submit" value="提交"> -->提交表单
效果图

1.7.2 下拉框

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 下拉框 -->
<select>
<option>北京</option>
<option>上海</option>
<option>深圳</option>
</select>

<!-- 下拉框多选,按住shift键点击目标 -->
<select multiple>
<option>北京</option>
<option>上海</option>
<option>深圳</option>
</select>
效果图

1.7.3 多行文本

1
2
3
<textarea></textarea>
<!-- rows="3" 默认支持写3行数据 -->
<textarea rows="3"></textarea>
效果图

1.8 HTML-表单和提交

页面上的数据,想要提交到后台:

  • form标签包裹要提交的数据的标签。
    • 提交方式:method="get"
    • 提交的地址:action="/xxx/xxx/xx" 默认不写为提交到当前地址
    • 在form标签里面必须有一个submit标签。
  • 在form里面的一些标签:input/select/textarea
    • 一定要写name属性,用于后端接收用户填写的数据 <input type="text" name="user"/>
1
2
3
4
5
<form action="/提交到的地址/" method="get/post 提交的方式">
用户名:<input type="text" name="user">
密码:<input type="password" name="pwd">
<input type="submit" value="提交">
</form>

2. CSS样式

css,专门用来“美化”标签。

  • 基础CSS,写简单页面 & 看懂 & 改。
  • 模块,调整和修改。

2.1 css应用方式

2.1.1 在标签上应用

1
2
<img src="..." style="height:100px" />
<div style="color:red;">中国联通</div>
效果图

2.1.2 在head标签中写style标签

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
color:red;
}
</style>
</head>
<body>

<h1 class='c1'>用户登录</h1>
<h1 class='c1'>用户登录</h1>
<h1 class='c1'>用户登录</h1>
<h1 class='c1'>用户登录</h1>

</body>
</html>
效果图

2.1.3 将css写到文件中并引用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- 引入common.css文件 -->
<link rel="stylesheet" href="common.css" />
</head>
<body>

<h1 class='c1'>用户登录</h1>
<h1 class='c2'>用户登录</h1>
<h1 class='c2'>用户登录</h1>
<h1 class='c1'>用户登录</h1>

</body>
</html>
1
2
3
4
5
6
7
8
/* common.css文件 */
.c1{
height:100px;
}

.c2{
color:red;
}
效果图

2.2 css选择器

2.2.1 ID选择器

1
2
3
4
5
#c1{

}

<div id='c1'></div>

2.2.2 类选择器(最多)

1
2
3
4
5
.c1{

}

<div clss='c1'></div>

2.2.3 标签选择器

1
2
3
4
5
div{

}

<div>xxx</div>

2.2.4 属性选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
input[type='text']{
border: 1px solid red;
}
.v1[xx="456"]{
color: gold;
}

<input type="text">
<input type="password">

<div class="v1" xx="123">s</div>
<div class="v1" xx="456">f</div>
<div class="v1" xx="999">a</div>

2.2.5 后代选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.yy li{
color: pink;
}
<!-- >只在儿子里面找标签 -->
.yy > a{
color: dodgerblue;
}


<div class="yy">
<a>百度</a>
<div>
<a>谷歌</a>
</div>
<ul>
<li>美国</li>
<li>日本</li>
<li>韩国</li>
</ul>
</div>

2.3 css选择器多个样式和覆盖问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
color: red;
border: 1px solid red;
}
.c2{
font-size: 28px;
color: green;
}
</style>
</head>
<body>
<div class="c1 c2">中国联通</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
color: red !important;
border: 1px solid red;
}
.c2{
font-size: 28px;
color: green;
}
</style>
</head>
<body>
<div class="c1 c2">中国联通</div>
</body>
</html>

2.4 css样式

2.4.1 认识块级和行内标签

1
2
3
行内标签:<a>、<b>、<i>、<s>、<u>、<em>、<del>、<ins>、<span>、<strong>
块级标签:<p>、<h1~h6>、<ul>、<ol>、<dl>、<li>、<dd>、<dt>、<div>、<form>、<table>
行内块标签:<img>、<input>、<textarea>、<select>、<td>、<label>
  • 区别:
特点 行内 块级 行内块
排列 一行多个 一行一个 一行多个
宽高 不可设置 可以设置 可以设置
默认宽度 内容撑开 100% 内容撑开

2.4.2 高度和宽度

1
2
3
4
.c1{
height: 300px; /* 高 */
width: 500px; /* 宽 */
}

注意事项:

  • 宽度,支持百分比。
  • 行内标签:默认无效
  • 块级标签:默认有效(霸道,右侧区域空白,也不给你占用)

2.4.3 块级+行内标签

  • 块级
  • 行内
  • css样式:标签 -> display:inline-block 既具备块级标签功能,又具有行内标签功能
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
display: inline-block;

height: 100px;
width: 300px;
border: 1px solid red;
}
</style>
</head>
<body>
<span class="c1">中国</span>

<span class="c1">联通</span>

<span class="c1">联通</span>

<span class="c1">联通</span>
</body>
</html>
效果图

2.4.4 块级和行内标签的设置

1
<div style="display: inline;">中国</div>
1
<span style="display: block;">联通</span>

2.4.5 字体和颜色

  • 颜色
  • 大小
  • 加粗
  • 字体样式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
color: #00FF7F;
font-size: 58px;
font-weight: 600;
font-family: Microsoft Yahei;
}
</style>
</head>
<body>
<div class="c1">中国联通</div>
</body>
</html>

2.4.6 文字对齐方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1{
height: 59px;
width: 300px;
border: 1px solid red; /* 边框 */

text-align: center; /* 水平方向居中 */
line-height: 59px; /* 垂直方向居中 */
}
</style>
</head>
<body>
<div class="c1">德玛西亚</div>
</body>
</html>
效果图

2.4.7 浮动

2.4.7.1 文字浮动
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<span>左边</span>
<span style="float: right">右边</span>
</div>
</body>
</html>
效果图
2.4.7.2 标签浮动
  • 如果块级标签浮动起来就不会那么霸道一个占一行了,自己有多宽就占多宽
  • 如果你让标签浮动起来之后,就会脱离文档流。
  • 在浮动的标签最下面加上clear: both 就不会脱离文档流
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.item {
float: left;
width: 280px;
height: 170px;
border: 1px solid red;
}
</style>
</head>
<body>
<div style="background-color: dodgerblue">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div style="clear: both;"></div>
</div>
<div>你哦啊呀</div>
</body>
</html>
效果图

2.4.8 内边距

  • 内边距,内部空出来的区域
  • padding:20px 上下左右边距都为20px
  • padding: 20px 10px 5px 20px; 按照【上右下左】设置
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.outer{
border: 1px solid red;
height: 200px;
width: 200px;

padding-top: 20px; /* 上边距 */
padding-left: 20px; /* 左边距 */
padding-right: 20px; /* 右边距 */
padding-bottom: 20px; /* 下边距 */
}
</style>
</head>
<body>
<div class="outer">
<div style="background-color: gold;">听妈妈的话</div>
<div>
小朋友你是否有很多问号
</div>
</div>
</body>
</html>
效果图

2.4.9 外边距

  • 外边距,我与别人加点距离。
  • margin-top:10px 自己不增大,距离外部有多少距离
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="height: 200px;background-color: dodgerblue;"></div>
<div style="background-color: red;height: 100px;margin-top: 20px;"></div>
</body>
</html>
效果图

2.4.10 小米商城案例

2.4.10.1 导航栏
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body { /* body默认有边距,把边距去除 */
margin: 0;
}

.header {
background: #333;
}

.container {
width: 1226px;
margin: 0 auto; /* 上下边距为0 左右自动设置,默认居中 */
}

.header .menu {
float: left;
color: white;
}

.header .account {
float: right;
color: white;
}

.header a {
color: #b0b0b0;
line-height: 40px;
display: inline-block;
font-size: 12px;
margin-right: 10px;
}
</style>
</head>
<body>

<div class="header">
<div class="container">
<div class="menu">
<a>小米商城</a>
<a>MIUI</a>
<a>云服务</a>
<a>有品</a>
<a>开放平台</a>
</div>
<div class="account">
<a>登录</a>
<a>注册</a>
<a>消息通知</a>
</div>
<div style="clear: both"></div>
</div>
</div>

</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
● body标签,默认有一个边距,造成页面四边都有白色间隙,如何去除呢?
body{
    margin: 0;
}

● 内容居中
  1. 文本居中,文本会在这个区域中居中。
  <div style="width: 200px; text-align: center;">武沛齐</div>

2. 区域居中,自己要有宽度 + margin-left:auto; margin-right:auto
.container{
width: 980px;
margin: 0 auto;
}

<div class="container">
哈哈哈哈哈
</div>

● 父亲没有高度或没有宽度,它会被孩子支撑起来。

● 如果存在浮动,一定记得加入 。
<div style="clear: both"></div>
效果图
2.4.10.2 二级菜单
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
}

.sub-header {
height: 100px;
}

.container {
width: 1128px;
margin: 0 auto;
}

.sub-header .ht {
height: 100px;
}

.sub-header .logo {
width: 234px;
float: left;

}

.sub-header .logo a {
margin-top: 22px;
display: inline-block
}

.sub-header .logo a img {
height: 56px;
width: 56px;
}

.sub-header .menu-list {
float: left;

line-height: 100px;
}

.sub-header .menu-list a{
display: inline-block;
padding: 0 10px;
color: #333;
font-size: 16px;
text-decoration: none;
}

.sub-header .menu-list a:hover{
color: #ff6700;
}

.sub-header .search {
float: right;
}
</style>
</head>
<body>
<div class="sub-header">
<div class="container">
<div class="ht logo">
<!-- a,行内标签;默认设置高度、边距无效。 -> 块级 & 行内+块级 -->
<a href="https://www.mi.com/">
<img src="../static/img/log.jpg" alt="">
</a>

</div>
<div class="ht menu-list">
<a href="https://www.mi.com/">Xiaomi手机</a>
<a href="https://www.mi.com/">Redmi红米</a>
<a href="https://www.mi.com/">电视</a>
<a href="https://www.mi.com/">笔记本</a>
<a href="https://www.mi.com/">平板</a>
</div>
<div class="ht search"></div>
<div class="clear:both;"></div>
</div>
</div>

</body>
</html>
效果图
2.4.10.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
}

.container {
width: 1226px;
margin: 0 auto;
}


.header {
background: #333;
}


.header .menu {
float: left;
color: white;
}

.header .account {
float: right;
color: white;
}

.header a {
color: #b0b0b0;
line-height: 40px;
display: inline-block;
font-size: 12px;
margin-right: 10px;

text-decoration: none;
}
.header a:hover{
color: white;
}

.sub-header {
height: 100px;
}

.sub-header .ht {
height: 100px;
}

.sub-header .logo {
width: 234px;
float: left;

}

.sub-header .logo a {
margin-top: 22px;
display: inline-block
}

.sub-header .logo a img {
height: 56px;
width: 56px;
}

.sub-header .menu-list {
float: left;

line-height: 100px;
}

.sub-header .menu-list a {
display: inline-block;
padding: 0 10px;
color: #333;
font-size: 16px;
text-decoration: none;
}

.sub-header .menu-list a:hover {
color: #ff6700;
}

.sub-header .search {
float: right;
}
</style>
</head>
<body>

<div class="header">
<div class="container">
<div class="menu">
<a href="https://www.mi.com/">小米商城</a>
<a href="https://www.mi.com/">MIUI</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/">有品</a>
<a href="https://www.mi.com/">开放平台</a>
</div>
<div class="account">
<a href="https://www.mi.com/">登录</a>
<a href="https://www.mi.com/">注册</a>
<a href="https://www.mi.com/">消息通知</a>
</div>
<div style="clear: both"></div>
</div>
</div>

<div class="sub-header">
<div class="container">
<div class="ht logo">
<!-- a,行内标签;默认设置高度、边距无效。 -> 块级 & 行内+块级 -->
<a href="https://www.mi.com/">
<img src="/static/img/log.jpg" alt="">
</a>

</div>
<div class="ht menu-list">
<a href="https://www.mi.com/">Xiaomi手机</a>
<a href="https://www.mi.com/">Redmi红米</a>
<a href="https://www.mi.com/">电视</a>
<a href="https://www.mi.com/">笔记本</a>
<a href="https://www.mi.com/">平板</a>
</div>
<div class="ht search"></div>
<div class="clear:both;"></div>
</div>
</div>


</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
a标签是行内标签,行内标签的高度、内外边距,默认无效。

● 垂直方向居中
1. 文本 + line-height
2. 图片 + 边距
a标签默认有下划线,如果需要删除添加
text-decoration: none;

● hover: 鼠标放上去之后样式,比如字体变色等
.c1:hover{
...
}
a:hover{

}
效果图
2.4.10.4 小米商城新品推荐区域
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
}

img {
width: 100%;
height: 100%;
}

.left {
float: left;
}

.container {
width: 1226px;
margin: 0 auto;
}


.header {
background: #333;
}


.header .menu {
float: left;
color: white;
}

.header .account {
float: right;
color: white;
}

.header a {
color: #b0b0b0;
line-height: 40px;
display: inline-block;
font-size: 12px;
margin-right: 10px;

text-decoration: none;
}

.header a:hover {
color: white;
}

.sub-header {
height: 100px;
}

.sub-header .ht {
height: 100px;
}

.sub-header .logo {
width: 234px;
float: left;

}

.sub-header .logo a {
margin-top: 22px;
display: inline-block
}

.sub-header .logo a img {
height: 56px;
width: 56px;
}

.sub-header .menu-list {
float: left;

line-height: 100px;
}

.sub-header .menu-list a {
display: inline-block;
padding: 0 10px;
color: #333;
font-size: 16px;
text-decoration: none;
}

.sub-header .menu-list a:hover {
color: #ff6700;
}

.sub-header .search {
float: right;
}

.slider .sd-img {
width: 1226px;
height: 460px;
}

.news{
margin-top: 14px;
}

.news .channel {
width: 228px;
height: 164px;
background-color: #5f5750;
padding: 3px;
}

.news .channel .item {
height: 82px;
width: 76px;
float: left;
text-align: center;
}
.news .channel .item a{
display: inline-block;
font-size: 12px;
padding-top: 18px;
color: #fff;
text-decoration: none;

opacity: 0.7;
}
.news .channel .item a:hover{
opacity: 1;
}
.news .channel .item img{
height: 24px;
width: 24px;
display: block;
margin: 0 auto 4px;

}

.news .list-item {
width: 316px;
height: 170px;
}

</style>
</head>
<body>

<div class="header">
<div class="container">
<div class="menu">
<a href="https://www.mi.com/">小米商城</a>
<a href="https://www.mi.com/">MIUI</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/">有品</a>
<a href="https://www.mi.com/">开放平台</a>
</div>
<div class="account">
<a href="https://www.mi.com/">登录</a>
<a href="https://www.mi.com/">注册</a>
<a href="https://www.mi.com/">消息通知</a>
</div>
<div style="clear: both"></div>
</div>
</div>

<div class="sub-header">
<div class="container">
<div class="ht logo">
<!-- a,行内标签;默认设置高度、边距无效。 -> 块级 & 行内+块级 -->
<a href="https://www.mi.com/">
<img src="images/logo-mi2.png" alt="">
</a>

</div>
<div class="ht menu-list">
<a href="https://www.mi.com/">Xiaomi手机</a>
<a href="https://www.mi.com/">Redmi红米</a>
<a href="https://www.mi.com/">电视</a>
<a href="https://www.mi.com/">笔记本</a>
<a href="https://www.mi.com/">平板</a>
</div>
<div class="ht search"></div>
<div class="clear:both;"></div>
</div>
</div>

<div class="slider">
<div class="container">
<div class="sd-img">
<img src="images/b1.jpeg" alt="">
</div>
</div>
</div>


<div class="news">
<div class="container">
<div class="channel left">
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="clear:both"></div>
</div>
<div class="list-item left" style="margin-left: 14px">
<img src="images/w1.jpeg"/>
</div>
<div class="list-item left" style="margin-left: 15px">
<img src="images/w2.jpeg"/>
</div>
<div class="list-item left" style="margin-left: 15px">
<img src="images/w3.jpeg"/>
</div>
<div class="clear:both"></div>
</div>
</div>


</body>
</html>
1
2
● 设置透明度:
opacity:0.5; /* 0 ~ 1 */
效果图

2.5 CSS知识点

2.5.1 hover(伪类)

  • 鼠标悬停显示,移开恢复默认值
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1 {
color: red;
font-size: 18px;
}

.c1:hover {
color: green;
font-size: 50px;
}

.c2 {
height: 300px;
width: 500px;
border: 3px solid red;
}

.c2:hover {
border: 3px solid green;
}

.download {
display: none; /* 默认隐藏 */
}

.app:hover .download { /* 把app下的download变为.... */
display: block;
}
.app:hover .title{
color: red;
}
</style>
</head>
<body>
<div class="c1">联通</div>
<div class="c2">广西</div>

<div class="app">
<div class="title">下载APP</div>
<div class="download">
<img src="images/qcode.png" alt="">
</div>
</div>

</body>
</html>

2.5.2 after(伪类)

  • 向尾部添加东西
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.c1:after{
content: "大帅哥";
}
</style>
</head>
<body>
<div class="c1">吴阳军</div>
<div class="c1">梁吉宁</div>
</body>
</html>
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.clearfix:after{
content: "";
display: block;
clear: both;
}
.item{
float: left;
}

</style>
</head>
<body>
<div class="clearfix">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>

2.5.3 定位position

  • fixed
  • relative
  • absolute
2.5.3.1 fixed
  • 固定在窗口的某个位置
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

.back{
position: fixed;
width: 60px;
height: 60px;
border: 1px solid red;

right: 10px;
bottom: 50px;
}
</style>
</head>
<body>

<div style="height: 1000px;background-color: #5f5750"></div>
<div class="back"></div>

</body>
</html>
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
}

.dialog {
position: fixed;
height: 300px;
width: 500px;
background-color: white;

left: 0;
right: 0;
margin: 0 auto;

top: 200px;

z-index: 1000;
}

.mask {
background-color: black;
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
opacity: 0.7;
z-index: 999;
}
</style>
</head>
<body>


<div style="height: 1000px">asdfasdfasd</div>


<div class="mask"></div>
<div class="dialog">ttt</div>


</body>
</html>

固定在窗口的某个位置:
效果图


对话框:
效果图

2.5.3.2 relative和absolute
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

.c1{
height: 300px;
width: 500px;
border: 1px solid red;
margin: 100px;

position: relative;
}
.c1 .c2{
height: 59px;
width: 59px;
background-color: #00FF7F;

position: absolute;
right: 20px;
bottom: 10px;
}
</style>
</head>
<body>
<div class="c1">

<div class="c2"></div>

</div>
</body>
</html>
效果图

2.5.4 小米商城下载app案例

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin: 0;
}

img {
width: 100%;
height: 100%;
}

.left {
float: left;
}

.container {
width: 1226px;
margin: 0 auto;
}


.header {
background: #333;
}


.header .menu {
float: left;
color: white;
}

.header .account {
float: right;
color: white;
}

.header a {
color: #b0b0b0;
line-height: 40px;
display: inline-block;
font-size: 12px;
margin-right: 10px;

text-decoration: none;
}

.header a:hover {
color: white;
}

.sub-header {
height: 100px;
}

.sub-header .ht {
height: 100px;
}

.sub-header .logo {
width: 234px;
float: left;

}

.sub-header .logo a {
margin-top: 22px;
display: inline-block
}

.sub-header .logo a img {
height: 56px;
width: 56px;
}

.sub-header .menu-list {
float: left;

line-height: 100px;
}

.sub-header .menu-list a {
display: inline-block;
padding: 0 10px;
color: #333;
font-size: 16px;
text-decoration: none;
}

.sub-header .menu-list a:hover {
color: #ff6700;
}

.sub-header .search {
float: right;
}

.slider .sd-img {
width: 1226px;
height: 460px;
}

.news {
margin-top: 14px;
}

.news .channel {
width: 228px;
height: 164px;
background-color: #5f5750;
padding: 3px;
}

.news .channel .item {
height: 82px;
width: 76px;
float: left;
text-align: center;
}

.news .channel .item a {
display: inline-block;
font-size: 12px;
padding-top: 18px;
color: #fff;
text-decoration: none;

opacity: 0.7;
}

.news .channel .item a:hover {
opacity: 1;
}

.news .channel .item img {
height: 24px;
width: 24px;
display: block;
margin: 0 auto 4px;

}

.news .list-item {
width: 316px;
height: 170px;
}

.app {
position: relative
}

.app .download {
position: absolute;
height: 100px;
width: 100px;
display: none;
}
.app:hover .download{
display: block;
}
</style>
</head>
<body>

<div class="header">
<div class="container">
<div class="menu">
<a href="https://www.mi.com/">小米商城</a>
<a href="https://www.mi.com/">MIUI</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/" class="app">下载app
<div class="download">
<img src="images/qcode.png" alt="">
</div>
</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/">云服务</a>
<a href="https://www.mi.com/">有品</a>
<a href="https://www.mi.com/">开放平台</a>
</div>
<div class="account">
<a href="https://www.mi.com/">登录</a>
<a href="https://www.mi.com/">注册</a>
<a href="https://www.mi.com/">消息通知</a>
</div>
<div style="clear: both"></div>
</div>
</div>

<div class="sub-header">
<div class="container">
<div class="ht logo">
<!-- a,行内标签;默认设置高度、边距无效。 -> 块级 & 行内+块级 -->
<a href="https://www.mi.com/">
<img src="images/logo-mi2.png" alt="">
</a>

</div>
<div class="ht menu-list">
<a href="https://www.mi.com/">Xiaomi手机</a>
<a href="https://www.mi.com/">Redmi红米</a>
<a href="https://www.mi.com/">电视</a>
<a href="https://www.mi.com/">笔记本</a>
<a href="https://www.mi.com/">平板</a>
</div>
<div class="ht search"></div>
<div class="clear:both;"></div>
</div>
</div>

<div class="slider">
<div class="container">
<div class="sd-img">
<img src="images/b1.jpeg" alt="">
</div>
</div>
</div>


<div class="news">
<div class="container">
<div class="channel left">
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="item">
<a href="https://www.mi.com/">
<img src="images/v1.png" alt="">
<span>保障服务</span>
</a>
</div>
<div class="clear:both"></div>
</div>
<div class="list-item left" style="margin-left: 14px">
<img src="images/w1.jpeg"/>
</div>
<div class="list-item left" style="margin-left: 15px">
<img src="images/w2.jpeg"/>
</div>
<div class="list-item left" style="margin-left: 15px">
<img src="images/w3.jpeg"/>
</div>
<div class="clear:both"></div>
</div>
</div>


</body>
</html>
效果图

2.5.5 border(边框)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

.c1{
height: 300px;
width: 500px;
border: 1px solid red; /* 默认 border宽细度 solid(实线)边框的样式 颜色*/
border-left: 3px solid #00FF7F; /* 只要左边框有颜色 */
margin: 100px;
}

</style>
</head>
<body>
<div class="c1"></div>
</body>
</html>
  • 鼠标移动边框变色
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

.c1{
height: 50px;
width: 500px;
margin: 100px;
background-color: #5f5750;
border-left: 2px solid transparent; /* transparent:透明边框 */
}

.c1:hover{
border-left: 2px solid red;
}

</style>
</head>
<body>
<div class="c1">菜单</div>
</body>
</html>

2.5.6 背景色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>

.c1{
height: 50px;
width: 500px;
margin: 100px;
background-color: red; /* 添加背景颜色 */
}


</style>
</head>
<body>
<div class="c1">菜单</div>
</body>
</html>
效果图