HTML

更新日志:

    2021.9.17:根据狂神说的视频整理出该笔记

    2022.4.18:由于学校前端选修课要考试了,根据沈大佬的笔记以及教学PPT做了一些修订和补充

关于前端的学习,这里推荐mdn文档

HTML

1. 初识html

全称是Hyper Text Market Language(超文本标记语言) , 而超文本指的是流媒体、图片、声音、视频等等.

1.1 特殊符号的表达

1
2
3
4
5
6
7
8
 <!--  特殊符号的样式  &   ; -->

<br/> <!--换行-->
<strong>i love you <strong> <!--粗体-->
<em>i love you<em> <!--斜体-->
&nbsp; <!--空格-->
&gt; <!--大于>-->
&lt; <!--小于<-->

1.2 行级元素和块级元素

类型 效果 例子
块级元素(block) 独占一行 div h p ul teble
行级元素(inline) 只占据内容的大小 span td a img

示例

HTML

HTML

一个行内元素通常会和其前后的其他行内元素显示在同一行中,不占有独立的区域,仅仅靠自身的字体大小和图像尺寸来支撑结构.一般不可以设置高度、对齐等属性,常用于控制页面中文本的样式

1.3 关于图片,视频和音频

1
2
3
4
5
6
7
8
9
10
11
12
<!--img 
src : 图片地址 相对地址 绝对地址 或者 图片的链接
alt : 图片的名字
-->
<img src = "../resources/imge/1.jpg" alt = "chen" title = "悬停文字" width = "100" height = "100">
<img src = "https://s2.loli.net/2022/04/13/qzsEFCRXW89Vc7I.jpg" alt = "chen" title = "悬停文字" width = "200" height = "250">

<!--视频和音频-->
<video src = "../resources/video/chen.mp4" > <!--同理这里也可以放链接-->
<video src = "../resources/video/chen.mp4" controls> <!--加上进度条-->
<video src = "../resources/video/chen.mp4" controls autoplay> <!--自动播放-->

示例

chen

1.4 超链接

1
2
3
4
5
6
7
<!--a标签
href : 必填,表示要跳转到的那个页面
target :表示窗口在哪里打开
_blank : 在新标签打开
_self: 在此窗口打开
-->
<a href = "https://space.bilibili.com/399488488" target = "_blank">点我</a>

示例

点我

1.5 锚链接

1
2
3
4
5
6
7
<!--锚链接
1. 需要一个锚标记
2. 跳转到标记
#
-->
<a href = "#" >回到顶部</a>

示例

回到顶部

1.6 功能性链接

1
2
3
<a href="mailto:chenning_william@163.com">点击联系我</a>

<hr/> 此为分割线

示例

点击联系我


此为分割线

1.7 列表

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
<!--有序列表-->
<ol>
<li>java</li>
<li>python</li>
<li>c/c++</li>
<li>运维</li>
</ol>


<!--无序列表-->
<ul>
<li>java</li>
<li>python</li>
<li>c/c++</li>
<li>运维</li>
</ul>

<!--自定义列表-->
<dl>
<dt>学科</dt>
<dd>c/c++</dd>
<dd>java</dd>
<dt>位置</dt>
<dd>成都</dd>
<dd>西安</dd>
</dl>

效果展示

  1. java
  2. python
  3. c/c++
  4. 运维
  • java
  • python
  • c/c++
  • 运维
学科
c/c++
java
位置
成都
西安

1.8 表格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<table>
<caption>表格标题</caption>
<tr>
<td>1-1</td>
<td>1-2</td>
<td>1-3</td>
<td>1-4</td>
</tr>
<tr>
<td>2-1</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
</tr>
<tr>
<td>3-1</td>
<td>3-2</td>
<td>3-3</td>
<td>3-4</td>
</tr>
</table>

效果展示

表格标题
1-1 1-2 1-3 1-4
2-1 2-2 2-3 2-4
3-1 3-2 3-3 3-4

colspan 跨列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<table> 
<tbody border = "1px"> <!--添加边线-->
<tr>
<td colspan = "4"> 1-1 </td> <!--跨四列-->
</tr>
<tr>
<td>2-1</td>
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
</tr>
<tr>
<td>3-1</td>
<td>3-2</td>
<td>3-3</td>
<td>3-4</td>
</tr>
</tbody>
</table>
1-1
2-1 2-2 2-3 2-4
3-1 3-2 3-3 3-4

rowspan 跨行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<table> 
<tbody border = "1px"><!--添加边线-->
<tr>
<td colspan = "4"> 1-1 </td> <!--跨四列-->
</tr>
<tr>
<!--rowspan 跨行-->
<td rowspan = "2"> 2-1 </td> <!--跨两行-->
<td>2-2</td>
<td>2-3</td>
<td>2-4</td>
</tr>
<tr>
<td>3-2</td>
<td>3-3</td>
<td>3-4</td>
</tr>
</tbody>
</table>
1-1
2-1 2-2 2-3 2-4
3-2 3-3 3-4

2. 页面结构分析

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>
</head>
<body>
<header>
<p>网页头部</p>
</header>
<section>
<p>网页主体</p>
</section>
<footer>
<p>网页脚部</p>
</footer>
</body>
</html>

head部分

HTML文档的头部标记主要包含页面标题标记、元信息标记、样式标记、脚本标记、链接标记等。头部标记所包含的信息一般不会显示在网页上

页面标题title

title标题信息显示在浏览器的标题栏上

元信息meta

META标记用来描述一个HTML网页文档的属性,也称为元信息(meta-information),这些信息并不会显示在浏览器的页面中。例如作者、日期和时间、网页描述、关键词、页面刷新等。<meta>标记位于文档的头部,其属性定义了与文档相关联的“名称/值”对。

name属性与content属性

name属性用于描述网页,它是以“名称/值”形式的名称,name属性的值所描述的内容(值)通过content属性表示,便于搜索引擎机器人查找、分类。其中最重要的是description、keywords和robots。

http-equiv属性与content属性

​ http-equiv属性用于提供HTTP协议的响应头报文(MIME文档头),它是以“名称/值”形式的名称,http-equiv属性的值所描述的内容(值)通过content属性表示,通常为网页加载前提供给浏览器等设备使用。其中最重要的是content-type charset提供编码信息,refresh刷新与跳转页面,no-cache页面缓存,expires网页缓存过期时间。

属性 描述
content some_text 定义与http-equiv或name属性相关的元信息
http-equiv content-type expires refresh set-cookie 把content属性关联到HTTP头部。内容类型网页缓存过期时间刷新与跳转(重定向)页面 如果网页过期,那么存盘的cookie将被删除
name author description keywords generator 把content属性关联到一个名称。定义网页作者 定义网页简短描述 定义网页关键词 定义编辑器
scheme some_text 定义用于翻译content属性值的格式。
1
2
3
4
5
6
7
<meta name="keywords" content="信息参数" />
<meta name="description" content="信息参数" />
<meta http-equiv="content-type" content="text/html; charset=信息参数" />
<meta name="generator" content="信息参数" />
<meta name="author" content="信息参数">
<meta http-equiv="refresh" content="时间; url=网址参数">
<meta name="robots" contect="信息参数">

body部分

元素名 描述
header 标题头部区域的内容(用于页面或页面中的一块区域)
footer 标题脚部区域的内容(用于整个页面或页面中的一块区域)
section Web页面中的一块独立区域
article 独立的文章内容
aside 相关内容或应用(常用于侧边栏)
nav 导航类辅助内容

在网页设计中,HTML提供了4种颜色设置方法:

  • 使用RGB(R,G,B),其中R、G、B是整数,取值范围:0~255;
  • 使用RGB(R%,G%,B%),其中R、G、B是整数,取值范围:0~100;
  • 使用3位或6位十六进制数#RGB或#RRGGBB,R、G、B为十六进制数,取值范围:0~9、A~F,每一种颜色用2位十六进制数表示,RR:红色部分,GG:绿色部分,BB:蓝色部分。红色为#FF0000;#RGB可以转换为#RRGGBB 。例如红色 分别 表示为#F00、#FF0000。
  • 使用颜色英文名称,如red表示红色,green表示绿色,blue表示蓝色等。

3. 内联框架

1
2
3
4
5
<!--
src : 引用页面的地址
name : 框架标识名
-->
<iframe src = "path" name = "mainFrame"></iframe>

嵌套网页

1
2
<!--示例嵌套网页-->
<iframe src="https://52hzmercury.github.io/" width="100%" height="500" name="topFrame" scrolling="yes" noresize="noresize" frameborder="0" id="topFrame"></iframe>

参数说明

width="100%" 为宽度自适应,高度请根据实际需求跳转, scrolling 为滚动条参数。frameborder 为边框参数。noresize 属性规定用户无法调整框架的大小。

嵌套B站视频

1
<iframe src="//player.bilibili.com/player.html?aid=375588815&bvid=BV1so4y1m7U5&cid=339262048&page=1&high_quality=1&danmaku=0" allowfullscreen="allowfullscreen" width="100%" height="500" scrolling="no" frameborder="0" sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts"></iframe>

参数说明

BILIBILI 地址PC端参数

  • &high_quality=1 (1=最高画质 0=最低画质)

  • &danmaku=0 (1=打开弹幕 0=关闭弹幕)

iframe 参数

  • allowfullscreen=“allowfullscreen” 移动端全屏
  • sandbox=“allow-top-navigation allow-same-origin allow-forms allow-scripts” 禁止弹出网页

4. 表单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!--表单from
action : 表单提交的位置,可以是网站,也可以是一个请求处理额地址
method : post ,get的提交方式
post: 速度较慢,但url上不会显示提交的数据,相对较安全
get: 速度较快,但url上会显示提交的数据,不太安全
-->
<form action = "chenkong.html" method = "get">

<!--文本输入框 : input type = "text"-->
<p>名字:<input type = "text" name = "username"></p>

<!--密码输入框 : input type = "password"-->
<p> 密码:<input type = "password" name = "pwd" ></p>
<p>
<input type = "submit">
<input type = "reset">
</p>
</form>

示例

名字:

密码:

4.1 表单元素的格式

属性 说明
type 指定元素的类型。text、password、checkbox、radio、submit、reset、file、hidden、ingage和button,默认为text
name 指定表单元素的名称
value 元素的初始值。type为radio时必须指定一个值
size 指定表单元素的宽度,当type为text或password时,表单元素的大小易字符为单位。对于其他类型,宽度以像素为单位
maxlength type为text或password时,输入的最大字符数
checked type为radio或checkbox时,指定按钮是否被选中

4.2 radio 单选器

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
<!--文本输入框:input type = "text"
value = "陈William牛逼" 默认初始值
maxlength = "8" 最长能写几个字符
size = "30" 文本框的长度
-->
<form action = "chenkong.html" method = "get">
<p>名字:<input type = "text" name = "username"></p>
<p> 密码:<input type = "password" name = "pwd" ></p>

<!--radio 单选器
input type = "radio"
value 单选框的值
name 表示组

-->
<span>
<input type = "radio" value = "boy" name = "sex">
</span>
<span>
<input type = "radio" value = "girl" name = "sex">
</span>
<!--这里的name属性必须要一样,表示他们是一个组的,这样就只能选一个了-->


<p>
<input type = "submit">
<input type = "reset">
</p>
</form>

示例

名字:

密码:

4.3 多选框

1
2
3
4
5
6
<input type = "checkbox" value = "sleep" name = hobby>睡觉
<input type = "checkbox" value = "code" name = hobby>敲代码
<input type = "checkbox" value = "chat" name = hobby>聊天
<input type = "checkbox" value = "game" name = hobby>游戏

<!--这也是在from表单里的-->

示例

睡觉 敲代码 聊天 游戏

4.4 关于按钮

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!--
input type = "buttion" 普通的按钮
input type = "image" 图像按钮 点击会提交 相当于submit
input type = "submit" 提交按钮
input type = "reset" 重置按钮
-->
<form action = "chenkong.html" method = "get">
<p>
<input type = "image" src = "https://s2.loli.net/2022/04/13/qzsEFCRXW89Vc7I.jpg" width = "50" height = "70">
</p>
<p>
<input type = "buttion" >
</p>
<p>
<input type = "submit">
</p>
<p>
<input type = "checkbox">
</p>
<p>
<input type = "reset">
</p>
</form>

示例

注意:

上图中在后面加上check后就是默认选中,图片的是可以提交的

4.5 下拉框

1
2
3
4
5
6
<select name = "列表名称">
<option value = "选项的值">中国</option>
<option value = "选项的值">美国</option>
<option value = "选项的值" selected>瑞士</option> <!--加上selected就是下拉框的默认选项值-->
<option value = "选项的值">印度</option>
</select>

示例

4.6 文本域

1
2
3
<p>
<textarea name = "textarea" cols = "50" rows = "10"> </textarea>
</p>

示例

4.7 文件域

input必须要有name属性,不然上传不了

1
2
3
4
<p>
<input type = "file" name = "files">
<input type = "button" value = "上传" name = "upload">
</p>

示例

4.8 简单的邮件地址和url验证验证

1
2
3
4
5
6
7
8
<form action = "chenkong.html" method = "get">
<p>
email: <input type = "email" name = "email">
</p>
<p>
url: <input type = "url" name = "url">
</p>
</form>

示例

email:

url:      

4.9 数字验证

1
2
3
<p>
<input type = "number" name = "num" max = "100" min = "0" step = "1">
</p>

示例

number:

4.10 滑块

1
<input type = "range" name = "vocie" min = "0" MAX = "100" step = "2">

示例

音量:

4.11 搜索框

1
<input type = "search" name = "search">

示例

搜索:

4.12 只读标签

1
<p>名字:<input type = "text" name = "username" value = "admin" readonly></p>

示例

名字:

4.13 禁用标签

加上 checked disabled

1
2
3
4
<p>
<input type = "radio" value = "boy" name = "sex" checked disabled/>
<input type = "radio" value = "girl" name = "sex"/>
</p>

示例

4.14 隐藏域

1
<p>密码<input type = "password" name = "pwd" hidden ></p>

示例

密码

在隐藏域中设置默认值

1
<p>密码<input type = "password" name = "pwd" hidden value = "123456" ></p>

4.15 增强鼠标

1
2
<label for = "mark">point</label>
<input type = "text" id = "mark">

点一下point,就可以到文本框中,增强鼠标的可用性

示例

4.16 表单的初级验证

常用方式

  • placeholder
  • required
  • pattern

placeholder

加上后会在框中有提示信息

1
<input type = "text" name = "username" placeholder = "请输入用户名">

示例

name:

required

使用户不能提交空,加上required

1
<input type = "text" name = "username" placeholder = "请输入用户名" required>

pattern

在pattern里面放入正则表达式判断

1
2
3
<p>
<input type = "text" name = "diyemail" pattern = "/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/">
</p>

上述正则的意思是:以数字字母开头中间可以是多个数字字符下划线或 ‘ - ’,然后是字符 ‘@’ ,后面是数字字符,最后是字符 ‘ . ’ 加上2-4个字母结尾。

5. 文本处理

5.1 标题字标记

1
2
3
4
5
6
7
<!--使用h1-h6和align控制-->
<h1 align="center" >Web前端开发技术</h1>
<h2 align="left" >Web前端开发技术</h2>
<h3 align="center" >Web前端开发技术</h3>
<h4 align="right" >Web前端开发技术</h4>
<h5 align="justify" >Web前端开发技术</h5> <!--均等对齐。有些浏览器不支持-->
<h6 align="center" >Web前端开发技术</h6>

示例

Web前端开发技术
Web前端开发技术
Web前端开发技术
Web前端开发技术
Web前端开发技术
Web前端开发技术

5.2 特殊符号

显示结果 说明 Entity Name
显示一个空格 &nbsp;
< 小于 &lt;
> 大于 &gt;
& &符号 &amp;
" 双引号 &quot;
© 版权 &copy;
® 注册商标 &reg;
× 乘号 &times;
÷ 除号 &divide;

5.3 物理样式标记

标记 说明
<b>软件工程专业!</b> 黑体
<i>软件工程专业!</i> 斜体
<u>软件工程专业!</u> 下划线
<del>软件工程专业!</del> 删除线
<small>软件工程专业!</samll> 变小字号
<big>软件工程专业!</big> 变大字号
<sup>软件工程专业!</sup> 上标
<sub>软件工程专业!</sub> 下标
<tt>软件工程专业!</tt> 打字机字体

5.4 换行

1
2
3
<br> 换行
<nobr> 不换行 </nobr>
<wbr> 强制换行 </wbr>

5.5 段落缩进

一对blockquote标记能够向右缩进5个西方字符的位置。

1
2
3
4
5
<h5 align="center">段落缩进标记的应用</h5>
<hr color="green">
没有缩进的文字内容
<blockquote>缩进的文字内容</blockquote>
<blockquote><blockquote>缩进的文字内容</blockquote></blockquote>

示例

段落缩进标记的应用

没有缩进的文字内容
缩进的文字内容
缩进的文字内容

5.6 预格式化标记

1
2
3
4
5
6
7
8
9
10
11

```html
<pre>预格式化文本 </pre >
<pre>
春 晓
孟浩然
春眠不觉晓,
处处闻啼鸟。
夜来风雨声,
花落知多少。
</pre>

示例

预格式化文本 
		  春 晓 			    
		    孟浩然 
         春眠不觉晓,
         处处闻啼鸟。
         夜来风雨声,
         花落知多少。

HTML
http://example.com/2021/09/17/HTML/
作者
Mercury
发布于
2021年9月17日
许可协议