HTML (Hyper Text Mackup Language,超文本标记语言)
超文本包括文字、图片、音频、视频等。
W3C标准
HTML基本结构
<!-- <!DOCTYPE 告诉浏览器,这个文本要使用什么标准> -->
<!-- 写DOCTYPE也可以,浏览器默认使用HTML标准 -->
<!DOCTYPE html>
<html lang="en">
<!-- 网页头部 -->
<head>
<!-- <meta> -- 用于描述网站信息 -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 可以用于SEO -->
<meta name="keywords" content="haha">
<meta name="description" content="hoho">
<title>Document</title>
</head>
<!-- 网页主体 -->
<body>
</body>
</html>
网页基本标签
标题标签
<h1>一级标签</h1>
<h2>二级标签</h2>
<h3>三级标签</h3>
<h4>四级标签</h4>
<h5>五级标签</h5>
<h6>六级标签</h6>
段落标签
换行标签
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网页基本标签</title>
</head>
<body>
在该标签中段文字都属于这一自然段<br/>
</body>
</html>
水平线标签
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网页基本标签</title>
</head>
<body>
<hr/>
</body>
</html>
字体样式标签
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网页基本标签</title>
</head>
<body>
<p><strong>粗体</strong></p>
<p><em>斜体</em></p>
<p><i>Italy</i></p>
</body>
</html>
注释和特殊符号
<!-- 注释 -->
空格
更多HTML特殊符号
图像标签
超链接标签及应用
页面间链接
从一个页面跳转到另一个页面
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>超链接标签及应用</title>
</head>
<body>
<!-- 在新页面打开链接 -->
<a href="https://www.jiumodiary.com" target="_blank">Text</a>
<!-- 在本页打开链接 -->
<a href="https://www.jiumodiary.com" target="_self">Text</a>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</body>
</html>
锚链接
<html lang="en">
<head>
<meta charset="UTF-8">
<title>超链接标签及应用</title>
</head>
<body>
<!-- 以id为锚点标记 -->
<p> <a href="https://www.jiumodiary.com" target="_blank" id="top">Text</a> </p>
<p> <a href="https://www.jiumodiary.com" target="_self">Text</a> </p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p>
<a href="https://www.jiumodiary.com" target="_blank">
<img src="https://www2.jiumodiary.com/images/front/eleps.png" alt="缺省文字" title="悬停文字">
</a>
</p>
<p> <a href="#top">回到顶部</a> </p>
<!-- 还可以实现任意页面任意锚点跳转 -->
<p> <a href="https://www.jiumodiary.com/#top"></a> </p>
</body>
</html>
功能性链接
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p>
<a href="mailto:[email protected]"></a>
</p>
</body>
</html>
块内元素和行内元素
列表标签
无序列表
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- unordered list -->
<ul>
<li>HTML5</li>
<li>CSS3</li>
<li>JavaScript</li>
</ul>
</body>
</html>
有序列表
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- ordered list -->
<ol>
<li>C++</li>
<li>Golang</li>
<li>Python</li>
</ol>
</body>
</html>
自定义列表
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- Defined List -->
<dl>
<!-- Defined Title -->
<dt>Descipline</dt>
<!-- Defined item -->
<dd>Math</dd>
<dd>English</dd>
<dd>Chinese</dd>
<dt>Week</dt>
<dd>Monday</dd>
<dd>Tuesday</dd>
</dl>
</body>
</html>
表格标签
为什么要使用表格?
- 简单通用
- 结构稳定
基本结构:
- 行
- 列
- 单元格
- 跨行
- 跨列
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1px">
<!-- th: table header -->
<th colspan="2px">A</th><th>B</th><th>C</th>
<!-- tr: table row -->
<tr>
<!-- td: table data -->
<td colspan="2px">1-1</td><td>1-2</td><td>1-3</td>
<td>2-1</td><td>2-2</td><td>2-3</td>
</tr>
<tr>
<!-- td: table data -->
<td rowspan="2px">1-1</td><td>1-2</td><td>1-3</td>
<td>2-1</td><td>2-2</td><td>2-3</td>
</tr>
</table>
</body>
</html>
媒体元素
Video
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<video src="a.mp4" controls="controls" autoplay="autoplay"></video>
</body>
</html>
Audio
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<audio src="a.mp3" controls="controls" autoplay="autoplay"></audio>
</body>
</html>
页面结构分析
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<header>
<h2>Header</h2>
</header>
<nav>
<h4>Navigation</h4>
</nav>
<section>
<h1>Section1</h1>
</section>
<article>
<h3>Article</h3>
</article>
<aside>
<h3>Aside</h3>
</aside>
<footer>
<h5>Footer</h5>
</footer>
</body>
</html>
iframe内联框架
在一个网页内嵌套另一些网页
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<iframe name="jiumodiary" src="https://www.jiumodiary.com" frameborder="0" width="500px" height="500px">jiumodiary</iframe>
<a href="https://www.bing.com" target="jiumodiary">在指定iframe中打开网页</a>
</body>
</html>
初识表单post和get提交
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="POST">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
文本框和单选框
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
按钮和多选框
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> Hobby:
A<input type="checkbox" name="hobby" value="A">
B<input type="checkbox" name="hobby" value="B">
C<input type="checkbox" name="hobby" value="C">
</p>
<p>
<input type="button" name="click" value="点击变长">
<!-- 图片按钮 -->
<input type="image" src="https://www2.jiumodiary.com/images/front/eleps.png">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
列表框、文本域和文件域
列表框、文本域和文件域
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> 下拉框:
<select name="options">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
文本域 Textarea
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> 下拉框:
<select name="options">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
搜索框滑块和简单验证
自带简单验证的组件
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> Email checking:
<input type="email" name="email">
</p>
<p> URL checking:
<input type="url" name="url">
</p>
<p> Number checking:
<input type="number" name="number" max="100" min="0" step="10">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
滑块
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> 滑块
<input type="range" name="range" max="100" min="0">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
搜索框
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p> 搜索框
<input type="search" name="search">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
表单的应用
- 隐藏域
- 只读
- 禁用
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username" readonly> </p>
<p> Password: <input type="password" name="password" hidden> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender" disabled>
Girl<input type="radio" value="girl" name="gender">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
Label
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username"> </p>
<p> Password: <input type="password" name="password"> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p>
<!-- 使用label可以增加鼠标的可用性,点文字如同点text框,即label所绑定的组件 -->
<label for="text">Text</label>
<input type="text" id="text">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
表单的初级验证
- placeholder
- required
- pattern正则表达式
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="url" method="POST | GET"> -->
<!-- Get:可以直接在submit的url里看到提交到数据,不安全,但是高效 -->
<!-- POST:在url里看不到提交到数据,但是也可以在inspect element里看到,可以后期加密 -->
<form action="https://www.jiumodiary.com" method="GET">
<p> UserName: <input type="text" name="username" placeholder="Please input user name"> </p>
<p> Password: <input type="password" name="password" required> </p>
<p> Gender:
Boy<input type="radio" value="boy" name="gender">
Girl<input type="radio" value="girl" name="gender">
</p>
<p>
<!-- 使用label可以增加鼠标的可用性,点文字如同点text框,即label所绑定的组件 -->
<label for="text">Text</label>
<input type="text" id="text" placeholder="Regex text checking" pattern="^\d">
</p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>