什么是HTML?
HTML超文本标记语言
HTML(HyperText Markup Language)是一门语言,所有的网页都是HTML编写出来的。HTML运行在浏览器上,HTML标签由浏览器来解析。
<html>
<head>
<title>MyHTML</title>
</head>
<body>
<font color = 'blue'>Hello MyHTML!</font>
</body>
</html>
.html
或以.htm
结束。<h1>-<h6>
:定义标题大小从h1到h6
<font>
:定义文本的字体、尺寸、颜色
html颜色表示:
red
、blue
rgb(0-255,0-255,0-255)
0-255
#ff0000
表示红色取满绿色不取蓝色不取<i>
:定义斜体文字
<u>
:定义文本下划线
<center>
:定义文本居中
<p>
:定义段落
<br>
:定义折行,相当于换行
<hr>
:定义水平线
运行效果:
代码:
<!--html5的标识-->
<!DOCTYPE html>
<html lang="en">
<head>
<!--定义当前页面的字符集-->
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<hr> <!--定义水平线-->
<center>
<u>
<font face="楷体" size="5" color="red">智子</font>
</u>
<hr>
<p>
这是新的一段
</p>
<p>
这是另一段
</p>
<i>
这是一段斜体文字
</i>
<br><!--折行-->
换行了
</center>
</body>
</html>
<img src = "路径" length = "尺寸" width = "尺寸">
:图片标签
<audio src = "路径" controls = "controls">
:图片标签
<video src = "路径" length = "尺寸" width = "尺寸" controls = "controls">
:图片标签
显示效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<hr>
<h3>
<center>
<font face="宋体" color = blue>壁纸<br>展示</font>
</center>
</h3>
<hr>
<img src="1%20(260).jpg" height="1080" width="1920">
</body>
</html>
<a href = "链接" target = "打开方式"
跳转方式_blank
表示于新页面中打开。_self
表示于当前页面打开。
运行效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<center>
<h3>
<a href = "https://blog.csdn.net/qq_55799677/article/details/122171257" target = “_self”> 不要点我</a>
</h3>
</center>
</body>
</html>
<li>
定义列表项
有序列表 <ol>
<ol>
<li>二次元</li>
<li>唯美</li>
<li>风景</li>
</ol>
无序列表<ul>
<ul>
<li>二次元</li>
<li>唯美</li>
<li>风景</li>
</ul>
type
设置项目符号
例如:
<ol type = "a">
<li>二次元</li>
<li>唯美</li>
<li>风景</li>
</ol>
<table 属性>
定义表格border
规定表格边框的宽度width
规定表格的宽度cellspacing
规定单元格之间的空白<th>
定义行align
定义表格内容对齐方式<td>
定义单元格rowspan
规定单元格可横跨的行数colspan
规定单元格可横跨的列数运行效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table border = "1" cellspacing="0" width = "500">
<tr>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
<th>专业</th>
</tr>
<tr align = "center">
<td>010</td>
<td>张三</td>
<td>18</td>
<td>计算机</td>
</tr>
<tr align = "center">
<td>020</td>
<td>李四</td>
<td>19</td>
<td>土木工程</td>
</tr>
<tr align = "center">
<td>020</td>
<td>王五</td>
<td>21</td>
<td>人力资源</td>
</tr>
</table>
</body>
</html>
将已有表格的单元格进行合并:
合并代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table border = "1" cellspacing="0" width = "500">
<tr>
<th colspan="2">学号</th>
<!-- <th>姓名</th>-->
<th>年龄</th>
<th>专业</th>
</tr>
<tr align = "center">
<td>010</td>
<td>张三</td>
<td>18</td>
<td>计算机</td>
</tr>
<tr align = "center">
<td rowspan="2">020</td>
<td>李四</td>
<td>19</td>
<td>土木工程</td>
</tr>
<tr align = "center">
<!-- <td>020</td>-->
<td>王五</td>
<td>21</td>
<td>人力资源</td>
</tr>
</table>
</body>
</html>
div
span
form
表单标签
属性:
action
指定表单数据提交的url
表单项要想被提交,则必须指定其name
属性
method
指定表单数据提交的方式
提交方式:
get
默认值
post
运行效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action = "#" method="get"> <!--#表示把表单的数据提交到当前html页面中-->
<input type = "text" name="username">
<input type = "submit">
</form>
</body>
</html>
运行效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="#" method="post">
<input type = "hidden" name = "id" value="123">
<label for="username">用户名:</label>
<input type="text" name="username" id="username"><br>
<label for="password">密 码:</label>
<input type="password" name="password" id="password"><br>
性别:<input type="radio" name="gender" value = "1" id = "male"> <label for = "male">男</label>
<input type="radio" name="gender" value = "2" id = "female"> <label for = "female">女</label>
<br>
爱好:<input type = "checkbox" name="hobby" value="1"> 旅游
<input type = "checkbox" name="hobby" value="2"> 运动
<input type = "checkbox" name="hobby" value="3"> 唱歌
<br>
头像:<input type = "file"><br>
城市:
<select name = "city">
<option>北京</option>
<option>广州</option>
<option>上海</option>
</select>
<br>
个人描述:<textarea cols="20" rows="5" name = "desc"></textarea>
<br>
<br>
<input type="submit" value="免费注册">
<input type = "reset" value = "重置">
<input type = "button" value = "button">
</form>
</body>
</html>