HTML简单标签
1,标签语法
-
标签必须一一配对,不能交叉嵌套
正确:<div><span>hello world!</span></div> 错误:<div><span>hello world</div></span>
-
标签必须正确的闭合
-
有内容的标签
正确:<div>hello world</div> 错误:<div>hello world!
-
无内容的标签
正确:<br/>1 错误:<br>2
-
-
属性必须有值,值必须用引号括起来
正确:<font color="#a52a2a">hello world!</font> 错误:<font color=red>hello world!</font> 错误:<font color>hello world!</font>
-
注释不能嵌套:
正确:<!--注释不能嵌套--> 错误:<!--注释不能嵌套<!--注释不能嵌套-->-->
代码整合:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>标签语法</title>
</head>
<body>
<!--标签不能使用交叉嵌套-->
正确:<div><span>hello world!</span></div>
错误:<div><span>hello world</div></span>
<hr/>
<!--标签必须正确闭合-->
<!--i:有内容的标签-->
正确:<div>hello world</div>
错误:<div>hello world!
<hr/>
<!--ii:没有内容的文本标签-->
正确:<br/>1
错误:<br>2
<hr/>
<!--属性必须有值,值必须加引号-->
正确:<font color="#a52a2a">hello world!</font>
错误:<font color=red>hello world!</font>
错误:<font color>hello world!</font>
<hr/>
<!--注释不能嵌套-->
正确:<!--注释不能嵌套-->
错误:<!--注释不能嵌套<!--注释不能嵌套-->-->
</body>
效果如图:
注意:有些地方出现了语法错误,但是在页面里的结果却是正确的是因为浏览器将我们的错误语法进行了纠正,所以出现了正确的结果。
2、font标签
font标签是一种字体标签,可以改变文字的颜色,大小和字体
- color:改变文字的颜色
- size:改变文字的大小
- face:改变文字的字体
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1-font标签</title>
</head>
<body>
<font color="#f5f5dc" size="7" face="宋体">hello world!</font>
</body>
</html>
3、特殊字符
一些特殊字符在html里面是特殊字符,如果想要在页面中显示它,那就要使用字符实体;
举个栗子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2-特殊字符</title>
</head>
<body>
我是<br>标签<br/>
hello world!!!!!!<br/>
hello world!!!!
</body>
</html>
效果如下图:
4、标题标签
标题标签一共有6种标签,从h1到h6,h1最大,h6最小
标题有一个常用属性align,它表示标题的对齐方式 ,常用的有以下3种:
- left:左对齐
- right:右对齐
- center:居中显示
<!DOCTYPE html>