HTML5
HTML5:HTML的第五个版本
HTML5新增内容(面试题)
1、语意化标签
主要给开发人员使用,不需要给标签起类名
2、智能表单
提前做好验证
3、视频、音频
替代flash
4、canvas、svg
主要用来绘图
5、离线存储、本地存储
主要用来存储数据
6、相关API
封装好的函数,只需要会使用
以上内容在多数浏览器中,已经得到了很好的兼容
常用浏览器:
IE----------------微软
chrome------------谷歌
firefox-----------火狐
safari------------苹果
opera-------------欧朋
HTML5语法:
1、文件后缀名不变,依然是.html或者.htm
2、指定编码格式为utf-8
3、不区分大小写
4、属性值的引号单引号,双引号均可
5、部分标签可以省略
1)单标签省略后面的/
<br/>==========<br>
<!DOCTYPE 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>Document</title>
</head>
<body>
<ul>
<li>我是文本内容
<li>我是文本内容
<li>我是文本内容
<li>我是文本内容
</ul>
</body>
</html>
2)双标签可以当成单标签来使用
p、li、dt
3)完全省略掉的标签
html、head、body、tbody
<!DOCTYPE html>
<style>
div{
background-color: pink;
}
</style>
<div>我是div标签</div>
语意化标签:
header----------------页面头
section---------------页面主体
footer----------------页面尾部
main------------------主要内容
nav-------------------导航
aside-----------------侧边栏
article---------------文章区域
figure----------------独立文档流区域
figcaption------------独立文档流标题
video-----------------视频
audio-----------------音频
<!DOCTYPE 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>Document</title>
<style>
header{
height:50px;
background-color: pink;
text-align: center;
line-height: 50px;
}
nav{
width:1200px;
line-height:100px;
margin:0 auto;
text-align: center;
background-color: yellowgreen;
}
section{
width:1200px;
height:800px;
margin:0 auto;
font-size: 50px;;
text-align: center;
background-color: plum;
}
main{
width:500px;
height:300px;
background-color: yellow;
}
footer{
line-height:100px;
text-align: center;
background-color: chartreuse;
}
</style>
</head>
<body>
<header>页面头部</header>
<nav>导航</nav>
<section>页面主体
<main>主要内容</main>
</section>
<footer>页面尾部</footer>
</body>
</html>
视频与音频
<video src="" ></video>
标签中的属性
src---------------视频路径
controls----------控件属性(添加此属性视频才显示播放按钮,进度条,音量等)
autoplay----------自动播放(单独使用不生效)
需要配合金银属性一起使用
muted-------------静音
loop--------------循环播放
poster------------视频播放前的加载封面
<!DOCTYPE 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>Document</title>
</head>
<body>
<video src="img/loveYou.mp4" controls poster="img/duigou.jpg"></video>
</body>
</html>
<audio src="" ></audio>
标签中的属性:
src---------------视频路径
controls----------控件属性(添加此属性视频才显示播放按钮,进度条,音量等)
autoplay----------自动播放(单独使用不生效)
需要配合金银属性一起使用
muted-------------静音
注意:autoplay与muted一起使用在谷歌浏览器中不能实现自动播放效果,可以在火狐浏览器中实现自动播放
loop--------------循环播放
<!DOCTYPE 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>Document</title>
</head>
<body>
<audio src="img/andrew spacey,tommy ice - Rear View.mp3" controls autoplay muted></audio>
</body>
</html>
智能表单:
input type属性取值
1、color
颜色拾取器
2、tel
拨号键盘
3、search
搜索框:输入内容后会显示叉号,用来清空输入框
4、range
滑块
属性:
value:表示滑块默认显示位置
min:设置滑块最小值(默认值:0)
max:设置滑块最大值(默认值:100)
step:表示每托动一下滑块更改的数值
5、email
邮箱输入框
如果内容为空,验证通过,可以提交表单
如果内容不为空,格式错误,会有提示弹窗,表单不能提交
如果内容正确,验证通过,表单可以提交
6、number
数值类型输入框
属性:
value:表示默认显示值
min:设置最小值
max:设置最大值
step:表示点击一下更改的数值
7、url
地址输入框
如果内容为空,验证通过,可以提交表单
如果内容不为空,格式错误,会有提示弹窗,表单不能提交
如果内容正确,验证通过,表单可以提交
8、date
日期(包含年月日)
9、month
月份(包含年月)
10、week
周期(包含年周)
11、time
时间
12、datetime-local
本地时间
<!DOCTYPE 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>Document</title>
</head>
<body>
<form action="http://www.baidu.com">
颜色拾取器: <input type="color"> <br>
拨号键盘: <input type="tel"> <br>
搜索框: <input type="search"> <br>
滑块:<input type="range" value="40" min="20" max="80" step="10"> <br>
邮箱:<input type="email"> <br>
数值:<input type="number" value="20" min="10" max="40" step="5"> <br>
地址输入框: <input type="url"> <br>
日期:<input type="date"> <br>
月份:<input type="month"> <br>
周期:<input type="week"> <br>
时间:<input type="time"> <br>
本地时间:<input type="datetime-local"> <br>
<input type="submit">
</form>
</body>
</html>
新增表单属性:
<!DOCTYPE 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>Document</title>
</head>
<body>
<form action="http://www.baidu.com">
用户名: <input type="text" placeholder="请输入用户名" value="张三" autofocus> <br>
昵称: <input type="text" placeholder="请输入昵称" name="user" autocomplete="on"> <br>
密码 <input type="password" placeholder="请输入密码" pattern="[0-9][A-Z]{3}"> <br>
邮箱:<input type="email" required multiple> <br>
<input type="submit">
</form>
</body>
</html>
1、数值与滑块中属性
min------最小值
max------最大值
step-----每操作一次更改的数值
2、必填属性(邮箱、地址输入框)
required
3、上传多个值
multiple
应用在邮箱输入框中,多个值之间用逗号分隔
4、提示信息
placeholder(内容用户不能编辑,只起到提示的作用)
5、自动获取光标
autofocus(一个页面只能有一个元素自动获取光标)
6、正则表达式验证
pattern
pattern="[0-9][A-Z]{3}"----------表示一个数字三个大写字母
7、自动提示文本
autocomplete
注意:一定要给标签添加name属性一起使用
8、模拟下拉列表(实现模糊搜索功能)
<!DOCTYPE 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>Document</title>
</head>
<body>
<input type="text" list="car">
<datalist id="car">
<option value="宝马">宝马</option>
<option value="奥迪">奥迪</option>
<option value="奔驰">奔驰</option>
<option value="宝骏">宝骏</option>
<option value="宝莱">宝莱</option>
<option value="蔚来">蔚来</option>
<option value="保时捷">保时捷</option>
<option value="奥特曼">奥特曼</option>
</datalist>
</body>
</html>