HTML5新特性
1.语义化标签 (★★)
<header>
头部标签<nav>
导航标签<article>
内容标签<section>
定义文档某个区域<aside>
侧边栏标签<footer>
尾部标签
总结
可以多次使用,并且命名,和div一样使用,只是语义化强一点
ie9以下不支持
2多媒体标签
2.1视频标签- video(★★★)
基本使用
当前 <video>
元素支持三种视频格式: 尽量使用 mp4格式
使用语法:
<video src="media/mi.mp4"></video>
兼容写法(仅了解)
<video controls="controls" width="300">
<source src="move.ogg" type="video/ogg" >
<source src="move.mp4" type="video/mp4" >
您的浏览器暂不支持 <video> 标签播放视频
</ video >
video 常用属性
属性很多,有一些属性需要大家重点掌握:
autoplay
自动播放- 注意: 在google浏览器上面,默认禁止了自动播放,如果想要自动播放的效果,需要设置 muted属性
width
宽度height
高度loop
循环播放src
播放源muted
静音播放
object-fit:
修改视频适应屏幕大小(了解)
示例代码:
<video src="media/mi.mp4" autoplay="autoplay" muted="muted" loop="loop" poster="media/mi9.jpg"></video>
2.2 audio 常用属性
示例代码:
<audio src="media/music.mp3" autoplay="autoplay" controls="controls"></audio>
小结
- 音频标签和视频标签使用方式基本一致
- 浏览器支持情况不同
- 谷歌浏览器把音频和视频自动播放禁止了
- 我们可以给视频标签添加 muted 属性来静音播放视频,音频不可以(可以通过JavaScript解决)
- 视频标签是重点,我们经常设置自动播放,不使用 controls 控件,循环和设置大小属性
3.新增的表单元素 (★★)
案例代码:
<!-- 我们验证的时候必须添加form表单域 -->
<form action="">
<ul>
<li>邮箱: <input type="email" /></li>
<li>网址: <input type="url" /></li>
<li>日期: <input type="date" /></li>
<li>时间: <input type="time" /></li>
<li>数量: <input type="number" /></li>
<li>手机号码: <input type="tel" /></li>
<li>搜索: <input type="search" /></li>
<li>颜色: <input type="color" /></li>
<!-- 当我们点击提交按钮就可以验证表单了 -->
<li> <input type="submit" value="提交"></li>
</ul>
</form>
常见输入类型
text password radio checkbox button file hidden submit reset image
新的输入类型
类型很多,我们现阶段重点记忆三个: number
tel
search
3.1新增的表单属性
1.required 表示内容不能为空
2.placeholder
设置默认文字,提示文本
input::placeholder{ color:pink}
可以通过伪元素来改变颜色
3.autofocus
自动聚焦属性,页面加载完成自动把鼠标定到搜索框里面
4.autocomplete="off"
已搜索过的内容关闭
5.multiple
选择多个文件提交
CSS3新特性
1 CSS3 新增选择器
快捷编辑方式:ul>(li>img[src=./photo$])*5
CSS3 给我们新增了选择器,可以更加便捷,更加自由的选择目标元素。
- 属性选择器
- 结构伪类选择器
- 伪元素选择器
1.1属性选择器(★★)
属性选择器,按照字面意思,都是根据标签中的属性来选择元素
[]前面不要加空格,如果有空格,那就是选择标签里面的属性了
示例代码:
/* 只选择 type =text 文本框的input 选取出来 */
input[type=text] {
color: pink;
}
/* 选择首先是div 然后 具有class属性 并且属性值 必须是 icon开头的这些元素 */
div[class^=icon] {
color: red;
}
/* 选择首先是section 然后 具有class属性 并且属性值 必须是 data结尾的这些元素 */
section[class$=data] {
color: blue;
}
- 属性选择器可以根据元素特定属性的来选择元素。 这样就可以不用借助于类或者id选择器
- 属性选择器也可以选择出来自定义的属性
- **注意:**类选择器、属性选择器、伪类选择器,权重为 10。
2结构伪类选择器
2.1 E:first-child
1.匹配父元素的第一个子元素E
ul li:first-child
选择第一个标签
**E:last-child**
选择最后一个li标签
2.2E:nth-child(n)(★★★)
ul li:nth-child(2){}
ul li:nth-child(odd){}
odd 或者2n+1 奇数
ul li:nth-child(even){}
even或者2n 偶数
2.3匹配到父元素的前3个子元素
ul li:nth-child(-n+3){}
2.3.1:nth-last-child(-n+5)
倒着数,选择后五个
2.4nth-child(n+5):nth-child(-n+9)(只要了解)
从第5个到第9个
2.5 E:nth-child 与 E:nth-of-type 的区别
E:nth-child(n)
匹配父元素的第n个子元素E,也就是说,nth-child 对父元素里面所有孩子排序选择(序号是固定的) 先找到第n个孩子,然后看看是否和E匹配
E:nth-of-type(n)
匹配同类型中的第n个同级兄弟元素E,也就是说,对父元素里面指定子元素进行排序选择。 先去匹配E ,然后再根据E, 找第n个孩子- 所有的查找方式和nth-child一摸一样
小结
- 结构伪类选择器一般用于选择父级里面的第几个孩子
- nth-child 对父元素里面所有孩子排序选择(序号是固定的) 先找到第n个孩子,然后看看是否和E匹配
- nth-of-type 对父元素里面指定子元素进行排序选择。 先去匹配E ,然后再根据E 找第n个孩子
- 关于 nth-child(n) 我们要知道 n 是从 0 开始计算的,要记住常用的公式
- 如果是无序列表,我们肯定用 nth-child 更多
- 类选择器、属性选择器、伪类选择器,权重为 10
3.伪元素选择器(★★★)
应用场景一: 字体图标
方法一:
步骤:
- 结构中定义div盒子
- 在style中先申明字体 @font-face
- 在style中定义after伪元素 div::after{…}
- 在after伪元素中 设置content属性,属性的值就是字体编码
- 在after伪元素中 设置font-family的属性
- 利用定位的方式,让伪元素定位到相应的位置;记住定位口诀:子绝父相
方法二:
link的方式只能加一个before 所以只能给一个标签
给div加class"iconfont icon-xxx"
<head>
...
<style>
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?1lv3na');
src: url('fonts/icomoon.eot?1lv3na#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?1lv3na') format('truetype'),
url('fonts/icomoon.woff?1lv3na') format('woff'),
url('fonts/icomoon.svg?1lv3na#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
div {
position: relative;
width: 200px;
height: 35px;
border: 1px solid red;
}
div::after {
position: absolute;
top: 10px;
right: 10px;
font-family: 'icomoon';
/* content: ''; */
content: '\e91e';
color: red;
font-size: 18px;
}
</style>
</head>
<body>
<div></div>
</body>
应用场景二: 仿土豆效果
1.鼠标经过盒子的时候 找到里面的a 添加after 伪元素
.box:hover a::before
2.经过盒子里面的a的时候 给a添加before
.box a:hover::before {
步骤:
- 创建.tudou 里面放img
- 给1.tudou 设置高宽 2.给Img设置w100% h100%
- 在style中,给大的div盒子(类名叫tudou的),设置!!!
::before
伪元素 - 这个伪元素充当的是遮罩的角色,所以我们不用设置内容,但是需要设置
content
属性,属性的值为空字符串 - 给这个遮罩设置宽高,背景颜色,默认是隐藏的 .
tudou::before{
- w 100% h100%
- 当鼠标移入到 div盒子时候,让遮罩显示,利用 hover 来实现
.tudou:hover::before{
<style>
.tudou {
position: relative;
width: 444px;
height: 320px;
background-color: pink;
margin: 30px auto;
}
.tudou img {
width: 100%;
height: 100%;
}
.tudou::before {
content: '';
/* 隐藏遮罩层 */
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .4) url(images/arr.png) no-repeat center;
}
/* 当我们鼠标经过了 土豆这个盒子,就让里面before遮罩层显示出来 */
.tudou:hover::before {
/* 而是显示元素 */
display: block;
}
</style>
</head>
<body>
<div class="tudou">
<img src="images/tudou.jpg" alt="">
</body>
应用场景三: 清除浮动
- 额外标签法也称为隔墙法,是 W3C 推荐的做法。
- 父级添加 overflow 属性
- 父级添加after伪元素
content,display:block,h=0,visibliety:hidden,clear:both
- 父级添加双伪元素
content,display:table,clear:both .clearfix:*zoom:1
4. 盒子模型(★★★)
box-sizing:默认content-box
盒子大小为width+padding+border
直接把这句话放到* {m0; p0; 后面}进行格式化
box-sizing: border-box 盒子大小为 width
前提是:padding和border不会超过盒子本身大小
如果盒子模型我们改为了box-sizing: border-box
, 那padding和border就不会撑大盒子了(前提padding和border不会超过width宽度)
5.模糊处理(了解) filter:blur();
blur()是一个函数,括号里面跟数值,单位是px.
一般是Img属性,数值越大,越模糊
filter:blur(10px)
5.1网页整体变灰色 filter:grayscle()
grayscle是一个函数,单位是px
filter:grayscle(1px)
6.计算盒子宽度 – calc 函数
补充:
定位居中positition:
top:calc(100%-自身盒子的一半)
left:calc(100%-自身盒子的一半)
这样就居中了
语法:
width: calc(100% - 80px);
括号里面可以使用 + - * / 来进行计算
7.过渡效果transition(重点)
1.过渡是属性值的变化,是从默认状态到结束状态之间一个变化的过程,过渡需要触发条件,(通常过渡都是添加默认状态,谁做过渡给谁加)
2.transiton:
要过渡得属性 花费时间S 运动曲线ease linear 何时开始
3.transition:width 1s,height 1s 1s;
这个让高度等1S,
如果用Hover 给定位,那么会一直抖动,因为 是honver得话,只是经过 你过了就没了.
简写:transition: all 1s;
如何让消失渐渐消失?
用display:none; 不能渐渐消失,因为是英文单词得变化.
如果是background-color:rgba(0,0,0,0) 只是让盒子透明,但是里面得内容不会消失
这个时候可以给opacity:0
取值0-1之间得小数,0是内容和盒子完全透明,1 不透明.
改了透明 这个盒子还在,还占位置,还要通过js判断.
7.1 小米下拉栏过渡效果案例
如果用margin-top,那么会导致结构错乱,下面的盒子偏移
这个时候要用transform:translate(x,y)单位px;
transform:translate(0,-5px)
.box ul li {
float: left;
width: 234px;
height: 300px;
background-color: pink;
margin: 50px;
transition: all 1s;
}
.box ul li:hover {
transform: translate(0, -5px);
}
7.2剑三
多行文本无法行高等于高居中
只能通过margin padding 才能居中
7.2 小米左上角Logo切换过渡效果案例
.logo {
overflow: hidden;
position: relative;
width: 55px;
height: 55px;
background-color: #ff3040;
margin: 100px auto;
}
.logo a {
position: absolute;
top: 0;
left: -55px;
width: 110px;
height: 55px;
transition: all 1s;
}
.logo:hover a {
left: 0;
}
.logo a::before {
float: left;
display: block;
content: "logo";
width: 55px;
height: 55px;
background-color: skyblue;
line-height: 55px;
}
.logo a::after {
float: left;
display: block;
content: "fangzi";
width: 55px;
height: 55px;
background-color: red;
line-height: 55px;
}
</style>
</head>
<body>
<div class="logo">
<a href="#"></a>
</div>
</body>
7.3 JD进度条过渡效果案例
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.bar {
overflow: hidden;
width: 100px;
height: 15px;
border: 1px solid red;
margin: 30px;
border-radius: 9px;
}
.bar-in {
width: 66%;
height: 15px;
background-color: red;
transition: all 0.5s;
}
.bar:hover .bar-in {
width: 95%;
}
</style>
</head>
<body>
<div class="bar">
<div class="bar-in"></div>
</div>
</body>
8.广泛得HTML5含义
1.广义得HTML5是HTML5本身+CSS3+JavaScript