FrontEnd笔记 -- HTML5

简介
  • 新特性
  1. 新增了audio和video音视频播放,抛弃了Flash
  2. 新增了canvas画布,用来进行绘画或制作动画(如小游戏开发等)
  3. 地理定位
  4. 增加了离线缓存
  5. 硬件加速
  6. Web Socket(全双工通信)
  7. 增加了本地存储
  8. 新增了一些语义化标签
  • 网页布局标签
    在这里插入图片描述
语义化标签
标签说明级别
mark高亮显示行级
details(描述)和summary(摘要)一般用于名词解释或用于封装一个区块等
meter定义度量衡,属性value/min/max
progress进度条,属性value/min/max
dialogue定义对话框或窗口
figure用于对元素进行组合,一般用来组合一张图的标题、图片和图片描述等
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
	<style type="text/css">
		body {
			overflow: hidden;
		}
		dialog {
			position: relative;
		}
		dialog span {
			position: absolute;
			padding: 10px;
			right: 0px;
			top: 0px;
			cursor: pointer;
		}

		figure {
			width: 200px;
			text-align: center;
		}
		figure img {
			width: 100%;
		}
		figure p {
			margin-top: -4px;
		}
	</style>
</head>
<body>
	<p><mark>FusionInsight HD</mark>:在Apache Hadoop开源生态圈的基础上,结合国内大数据未来应用场景给出的一套综合性解决方案。</p>

	<details>
		<summary>大前端开发</summary>
		<h2>大前端开发包括:</h2>
		<ul>
			<li>组件化开发</li>
			<li>模块化开发</li>
			<li>自动化开发</li>
			<li>后台开发</li>
		</ul>
	</details>

	<meter value="100" min="80" max="120"></meter>
	<p>任务已完成:<progress value="37" max="100"></p>
	
	<!-- 为什么不显示呢? -->
	<dialog open>
		<span>&times;</span>
		<h2>大前端开发包括:</h2>
		<ul>
			<li>组件化开发</li>
			<li>模块化开发</li>
			<li>自动化开发</li>
			<li>后台开发</li>
		</ul>
	</dialog>

	<figure>
		<h4>夏日风情</h4>
		<img src="http://www.loveyd.com/upimg/allimgs/080513/03404711.jpg" alt="夏日风情">
		<p>花儿朵朵开,心情无限好</p>
	</figure>
</body>
</html>
多媒体
  • audio

播放音乐或音频,支持的格式 .mp3/.ogg/.wav

属性说明
src文件路径
autoplay自动播放
loop循环
controls控制条
muted静音
preload预加载,当使用autoplay时失效
  • video

播放视频,支持的格式 .mp4/.ogg/.webm

属性说明
src文件路径
autoplay自动播放
loop循环
controls控制条
muted静音
preload预加载,当使用autoplay时失效
width宽度
height高度
poster海报
  • embed

嵌入内容或加载插件

属性说明
src文件路径
autoplay自动播放
width宽度
height高度
type类型
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<audio src="/path/to/target.mp3" controls autoplay loop="2"></audio>
	<video src="/path/to/target.mp4" autoplay controls loop="2" width="400" poster="http://www.loveyd.com/upimg/allimgs/080513/03404711.jpg"></video>
	<embed src="/path/to/target.swf" type="application/x-shockwave-flash"></embed>
</body>
</html>
  • canvas

画布,是一个容器元素(单独使用canvas没有什么意义,它必须结合JS使用;canvas的宽高最好不要通过css实现,而是直接使用标签属性width和height实现)。

<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<canvas width="400" height="200" style="background: yellow"></canvas>
</body>
<script type="text/javascript">
	// DOM操作,用来获取canvas元素
	var canvas = document.getElementsByTagName('canvas')[0];
	var ctx = canvas.getContext('2d');
	ctx.fillStyle = '#ff0000'; // 设置填充色
	ctx.fillRect(50,70,200,100); // 绘制一个矩形
</script>
</html>
新增常用属性
属性说明
contentEditable将标签转换为可编辑状态,可用于所有标签,值true/false
hidden对元素进行隐藏,一般用来传值或当某个条件成立时,执行内容显示
data-*用于存储页面或应用程序的私有自定义数据,一般用于传值
multiple规定输入域中可以选择多个内容,用于表单组件file/select中
required约束表单元素再提交前必须输入值;用于表单组件中,需要结合提交按钮使用
pattern用于验证输入字段的模式;用于表单组件中,需要结合提交按钮使用
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<p contenteditable="true">contenteditable</p>

	<div class="box">box1</div>
	<div class="box" hidden>box2</div>
	<div class="box">box3</div>

	<p data-id="00001">这是内容</p>

	<select multiple="">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
	</select>

	<form action="#">
		<input type="text" placeholder="请输入用户名" required><br>
		<input type="email" placeholder="请输入邮箱"><br>
		<input type="submit">
	</form>

	<form action="#">
		<input type="text" pattern="[A-Za-z0-9]{6,8}"><br>
		<input type="submit">
	</form>
</body>
</html>
表单新增内容
  • 新增表单组件
组件说明
color颜色
email邮箱
tel电话
url网址
number数字
range范围
search搜索
date日期
datetime日期时间
datetime-local本地日期时间
year
month
time时间
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<form action="#">
		<input type="color"><br>
		<!-- 包含验证 -->
		<input type="email"><br>
		<input type="tel"><br>
		<input type="url"><br>
		<input type="number" step="10" min="-100" max="100"><br>
		<input type="range" value="20" max="100"><br>
		<input type="search"><br>
		<input type="date"><br>
		<input type="datetime"><br>
		<input type="datetime-local"><br>
		<input type="week"><br>
		<input type="month"><br>
		<input type="year"><br>
		<input type="time"><br>
		<input type="submit">
	</form>
</body>
</html>
  • 新增表单属性
属性说明
formaction修改action数据提交的地方
formenctype修改表单请求的类型
formmethod修改数据提交的方法
form设置表单元素属于哪个表单
novalidate不验证
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<form action="//baidu.com">
		<input type="submit" formaction="//163.com">
	</form>

	<form action="#" enctype="application/x-www-form-urlencoded"><!-- 普通表单类型 -->
		<input type="submit" formenctype="multipart/form-data"><!-- 文件上传的类型 -->
	</form>

	<form action="#" method="get">
		<input type="text" name="username">
		<input type="submit" formmethod="post">
	</form>

	<form action="#" id="user-info">
		<input type="text" name="username">
		<input type="submit">
	</form>
	<input type="password" name="userpwd" form="user-info">

	<form action="#" method="get" novalidate>
		<input type="email" name="useremail">
		<input type="submit">
	</form>
</body>
</html>
  • 新增input属性
属性说明
*autocomplete自动完成;用来帮助用户输入,每一次输入的内容,浏览器是否保存输入的值,以备将来使用;值有on/off;为了保护敏感数据(如账户密码等),避免本地浏览器对它们进行不安全存储,一般需要关闭
*autofocus自动获焦
step步长
multiple多选
pattern正则匹配
*placeholder输入提示
required必须输入
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
</head>
<body>
	<form action="#">
		<input type="text" name="username" autocomplete="off">
		<input type="submit">
	</form>

	<form action="#">
		<input type="text" name="username" autofocus>
		<input type="submit">
	</form>

	<form action="#">
		<input type="text" name="username" placeholder="请输入用户名">
		<input type="submit">
	</form>
</body>
</html>
小练习
  • 效果图

在这里插入图片描述

  • HTML
<!-- 在线运行网站:https://www.runoob.com/runcode-->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>SimWor</title>
	<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lobster">
	<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Belgrano">
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
	<!-- 页面由上下两部分组成 -->
	<!-- 内容区 -->
	<div class="container">
		<aside>
			<div class="logo">
			<!-- h1标签在这里主要用于增加SEO -->
				<h1><a href="#">Corn Food</a></h1>
			</div>
			<nav>
				<ul class="navlist">
					<li><a class="active" href="#">Home</a></li>
					<li><a href="#">About</a></li>
					<li><a href="#">Shop</a></li>
					<li><a href="#">Customers</a></li>
					<li><a href="#">Contact</a></li>
				</ul>
				<audio src="material/Itsok.mp3" autoplay controls></audio>
			</nav>
		</aside>
		<main>
			<!-- 动画 -->
			<section>
				<object data="material/spring.swf" type="application/x-shockwave-flash" width="719" height="428">
				</object>
			</section>
			<!-- 分类文章 -->
			<section>
				<article>
					<a href="#">
						<h2>Type and scrambled it to make a type</h2>
						<video src="material/mov.ogg" controls width="163" height="112"></video>
					</a>
					<p class="small-post">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer</p>
					<p class="date"><span> Jun 30, 2012 </span><a href="#">{ Continue! }</a></p>
				</article>
				<article>
					<a href="#">
						<h2>Lorem Ipsum has been the industry's</h2>
						<video src="material/mov.ogg" controls width="163" height="112"></video>
					</a>
					<p class="small-post">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer</p>
					<p class="date"><span> Jun 30, 2012 </span><a href="#">{ Continue! }</a></p>
				</article>
				<article>
					<a href="#">
						<h2>The industry's standard dummy text</h2>
						<video src="material/mov.ogg" controls width="163" height="112"></video>
					</a>
					<p class="small-post">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer</p>
					<p class="date"><span> Jun 30, 2012 </span><a href="#">{ Continue! }</a></p>
				</article>
			</section>
			<div class="clear"></div>
			<!-- 关于 -->
			<section>
				<h2>About</h2>
				<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,</p>
				<p class="read-more">
					<a href="#">{Read More!}</a>
				</p>
			</section>
		</main>
	</div>
	<!-- 页尾 -->
	<footer>
		<p>
			Copyright © Your Company Name. All rights reserved. Collect Form 网页模板, Validation <a href="">HTML5</a>|<a href="">CSS3</a>
		</p>
	</footer>
</body>
</html>
  • CSS
* {
	margin: 0;
	padding: 0;
}
a {
	text-decoration: none;
	color: #900000;
}
li {
	list-style-type: none;
}
body {
	font-family: Belgrano, serif;
	font-size: 14px;
	background: url(material/siteBackground.jpg);
	padding-top: 10px;
	color: #452200;
}
.container {
	width: 1100px;
	margin: 0 auto;
	overflow: hidden;
}
aside {
	float: left;
	width: 320px;
}
/*logo*/
.logo {
	float: left;
	background: url(material/logoBackground.png) no-repeat;
	width: 206px;
	height: 205px;
}
.logo h1 {
	font-size: 60px;
	color: #883b12;
	font-family: Lobster, sans-serif;
	line-height: 60px;
	padding: 43px 0 0 43px;
}
.logo h1 a {
	color: #5a270b;
	/* 设置文字的阴影:横向偏移、纵向偏移、弧度、颜色 */
	text-shadow: 1px 1px 1px #fff;
}
/*导航*/
.navlist {
	padding-right: 40px;
	text-align: center;
}
.navlist li {
	padding: 5px 0;
	font-family: Lobster, sans-serif;
	text-shadow: 1px 1px 1px #fff;
	font-size: 36px;
}
.navlist li a {
	color: #ac8829;
}
.navlist li a:hover {
	color: #452200;
}
.navlist li a.active {
	color: #452200;
}
/*内容区*/
main {
	float: right;
	width: 750px;
}
main article {
	width: 193px;
	float: left;
	margin: 0 57px 27px 0;
}
main h2 {
	font-family: Lobster, sans-serif;
	font-size: 30px;
	padding: 10px 0;
	color: #883b12;
	text-shadow: 1px 1px 2px #fff;
}
main .title {
	line-height: 2em;
}
main article a h2:hover {
	color: #452200;
}
main p {
	line-height: 1.5em;
}
.date, .read-more {
	font-weight: bold;
	font-style: italic;
	font-size: 14px;
	margin-top: 10px;
}
main .date span {
	color: #ac8829;
}
.clear {
	clear: both;
}
/* 页尾 */
footer {
	width: 1100px;
	margin: 30px auto 0;
	text-align: center;
	border-top: 1px solid #ac8829;
}
footer p {
	padding: 30px 20px;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值