HTML5新增的几个布局和表单标签
CSS3的几个新增特性
2、HTML5提高-新增语义化标签
1、只兼容IE9以上版本浏览器和移动端
2、新增的语义化的标签(就是div标签变了个名字,只不过有更好的功能分工,使用方法也和标签没有区别)
注意:
①这些标签主要针对搜索引擎
②在标签页面中可以使用多次
③在IE9中,需要把这些元素转换为块级元素
④移动端更喜欢这些标签
3、4、HTML5新增的多媒体标签
1、音频<audio>
①支持格式mp3、wav、ogg(尽量使用mp3)
②语法:
<audio src="文件地址" 其他属性可选></audio>
③属性:
eg:<audio src="media/music.mp3" autoplay="autoplay" controls="controls"></audio>
2、视频<video>
①当前视频标签只支持三总视频格式:MP4,WebM,Ogg(尽量放mp4格式)
②语法:
<video src="文件地址" 其他属性可选></video>
③常见属性:
eg:<video src="media/mi.mp4" autoplay="autoplay" muted="muted" loop="loop" poster="media/mi9.jpg"></video>
总结:
使用他们可以很方便的在页面中嵌入音频和视频,而不再去使用flash和其他浏览器插件
5、HTML5新增的input特性<input type="。。" />
!!!验证的时候必须添加form表单域,点击提交按钮就可以验证表单了!!!
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- 我们验证的时候必须添加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>
</body>
</html>
效果如下:
注:移动端也可以使用
06、HTML5新增的表单属性<input type="file" name="" id="" 新属性="属性值">
!!!验证的时候必须添加form表单域,点击提交按钮就可以验证表单了!!!
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML5新增表单属性</title>
<style>
/* 修改表单中的属性文字!!! */
input::placeholder {
color: pink;
}
</style>
</head>
<body>
<form action="">
<input type="search" name="sear" id="" required="required" placeholder="pink老师" autofocus="autofocus" autocomplete="off">
<input type="file" name="" id="" multiple="multiple">
<input type="submit" value="提交">
</form>
</body>
</html>
07-16课、CSS3新增属性选择器
现状:发展阶段,移动端支持优于PC端
CSS3新增了选择器,可以更加便捷,更加自由的选择目标元素
1、属性选择器
可以根据元素特定的属性来选择元素,这样就可以不用借助于类或者id选择器
第二个是重点
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS3新增属性选择器</title>
<style>
/* 1、必须是input 但是同时具有 value这个属性 选择这个元素 [] */
input[value] {
color: pink;
}
/* 2、只选择 type =text 文本框的input 选取出来 */
input[type=text] {
color: pink;
}
/* 3、选择首先是div 然后 具有class属性 并且属性值 必须是 icon开头的这些元素 */
div[class^=icon] {
color: red;
}
/* 4、选择首先是section 然后 具有class属性 并且属性值 必须是 data结尾的这些元素 */
section[class$=data] {
color: blue;
}
div.icon1 {
color: skyblue;
}
/* !!!!!!!!类选择器和属性选择器 伪类选择器 权重都是 10!!!!!!!!!!! */
</style>
</head>
<body>
<!-- 1. 利用属性选择器就可以不用借助于类或者id选择器 -->
<input type="text" value="请输入用户名">
<input type="text">
<!-- 2. 属性选择器还可以选择属性=值的某些元素 重点务必掌握的 -->
<input type="text" name="" id="">
<input type="password" name="" id="">
<!-- 3. 属性选择器可以选择属性值开头的某些元素 -->
<div class="icon1">小图标1</div>
<div class="icon2">小图标2</div>
<div class="icon3">小图标3</div>
<div class="icon4">小图标4</div>
<div>我是打酱油的</div>
<!-- 4. 属性选择器可以选择属性值结尾的某些元素 -->
<section class="icon1-data">我是安其拉</section>
<section class="icon2-data">我是哥斯拉</section>
<section class="icon3-ico">哪我是谁</section>
</body>
</html>
2、结构伪类选择器
结构伪类选择器主要根据文档结构来选择器元素,常用于根据父级选择器里面的子元素
eg:
以下例子中的li
可以不加,这里加上是为了指明要ul的第一个孩子,而且这个孩子必须是li
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS3新增结构伪类选择器</title>
<style>
/* 1. 选择ul里面的第一个孩子 小li */
ul li:first-child {
background-color: pink;
}
/* 2. 选择ul里面的最后一个孩子 小li */
ul li:last-child {
background-color: pink;
}
/* 3. 选择ul里面的第2、6个孩子 小li */
ul li:nth-child(2) {
background-color: skyblue;
}
ul li:nth-child(6) {
background-color: skyblue;
}
</style>
</head>
<body>
<ul>
<li>我是第1个孩子</li>
<li>我是第2个孩子</li>
<li>我是第3个孩子</li>
<li>我是第4个孩子</li>
<li>我是第5个孩子</li>
<li>我是第6个孩子</li>
<li>我是第7个孩子</li>
<li>我是第8个孩子</li>
</ul>
</body>
</html>
1)、其中重点讲解一下nth-child(n)
的用法:
①功能:选择某个父元素的一个或多个特定的子元素
②其中n可以是数字,关键字和公式
③n如果是数字,就是选择第n个子元素,里面数字从1开始
④n也可以是关键字:even
偶数、odd
奇数
eg:
/* 1.把所有的偶数 even的孩子选出来 */
ul li:nth-child(even) {
background-color: #ccc;
}
/* 2.把所有的奇数 odd的孩子选出来 */
ul li:nth-child(odd) {
background-color: gray;
}
⑤nth-child(n)
表示直接选择所有的孩子(只能写n不能是其他字母)
eg:
/* 3.nth-child(n) 从0开始 每次加1 往后面计算 这里面必须是n 不能是其他的字母 选择了所有的孩子*/
ol li:nth-child(n) {
background-color: pink;
}
⑥n也可以是公式:
/* 4.nth-child(2n)母选择了所有的偶数孩子 等价于 even*/
ol li:nth-child(2n) {
background-color: pink;
}
/* 选择所有奇数 */
ol li:nth-child(2n+1) {
background-color: skyblue;
}
/* 每隔5个选择一个(5,10,15...) */
ol li:nth-child(5n) {
background-color: pink;
}
/* 从第3个开始选择 */
ol li:nth-child(n+3) {
background-color: pink;
}
/* 选择前3个 */
ol li:nth-child(-n+3) {
background-color: pink;
}
2)、nth-child
和nth-of-type
的区别
①nth-child
先排序,再分类
所以以下代码什么也不会选出来
/* nth-child 会把所有的盒子都排列序号 */
/* !!!!!!执行的时候首先看 :nth-child(1) 之后回去看 前面 div !!!!!!!*/
section div:nth-child(1) {
background-color: red;
}
<section>
<p>光头强</p>
<div>熊大</div>
<div>熊二</div>
</section>
②nth-of-type
先分类再排序
所以以下代码会把“熊大”选出来
/* nth-of-type 会把指定元素的盒子排列序号 */
/* 执行的时候首先看 div指定的元素 之后回去看 :nth-of-type(1) 第几个孩子 */
section div:nth-of-type(1) {
background-color: blue;
}
<section>
<p>光头强</p>
<div>熊大</div>
<div>熊二</div>
</section>
总结:
3、伪元素选择器(重点)
伪元素选择器可以帮助我们利用CSS创建新标签元素,而不需要HTML标签,从而简化HTML结构。
(比如视频的遮罩层等。。)
1)伪元素选择器:(双冒号)
注意
1、before和after创建一个元素,但是属于行内元素
2、新创建的这个元素在文档树中是找不到的,所以我们称为伪元素
3、语法element::before{}
4、before和after必须有content属性
5、before在父元素内容的前面创建元素,after在父元素内容的后面插入元素
6、伪元素选择器和标签选择器的权重一样,都是1
2)、基本使用:
eg1、
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>伪元素选择器before和after</title>
<style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
/* div::before 权重是2 */
div::before {
content: '我';
}
div::after {
content: '小猪佩奇';
}
</style>
</head>
<body>
<div>
是
</div>
</body>
</html>
结果如图:('我’在前面‘小猪佩奇’在后面)
由于伪类选择器创建的元素是行内元素,不能修改宽高,如果想要修改宽高,就需要转换为行内块元素:
div::before {
/* 这个content是必须要写的 */
display: inline-block;
content: '我';
width: 30px;
height: 40px;
background-color: purple;
}
3)伪元素选择器的3个使用场景
使用场景1——伪元素字体图标:
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>伪元素选择器使用场景-字体图标</title>
<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>
</html>
使用场景2——仿土豆效果
!!!结构永远比样式更重要,所以宁可放弃样式的简洁性,也要让结构更简单!!!
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>伪元素选择器使用场景2-仿土豆网显示隐藏遮罩案例</title>
<style>
.tudou {
position: relative;
width: 444px;
height: 320px;
background-color: pink;
margin: 30px auto;
}
.tudou img {
width: 100%;
height: 100%;
}
/* 伪类选择器,可以看做在tudou标签中加了一个叫before的伪标签,然后设置这个标签的内容 */
.tudou::before {
/* content是必须要有的 */
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="">
</div>
<div class="tudou">
<img src="images/tudou.jpg" alt="">
</div>
<div class="tudou">
<img src="images/tudou.jpg" alt="">
</div>
<div class="tudou">
<img src="images/tudou.jpg" alt="">
</div>
</body>
</html>
使用场景3——伪元素清除浮动的本质
1、之前介绍的几个方法
①额外标签法也称隔墙法,是W3C推荐的做法
②父级加overflow
伪元素清除浮动(更推荐)(③和④)
③父级加after
④父级添加双伪元素
17课、CSS3盒子模型border-box
1、CSS3中可以通过box-sizing
来指定盒子模型:
有2个值:即可指定为content-box
、border-box
、这样我们计算盒子大小的方式就发生了变化
eg;
div {
width: 200px;
height: 200px;
background-color: pink;
border: 20px solid red;
padding: 15px;
/* 会撑开盒子的做法 */
box-sizing: content-box;
}
p {
width: 200px;
height: 200px;
background-color: pink;
border: 20px solid red;
padding: 15px;
/*不会撑开盒子的做法: css3 盒子模型 盒子最终的大小就是 width 200 的大小 */
box-sizing: border-box;
}
以后只需要在这里
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
写好就行了
18、CSS图片模糊处理filter+blur
1、css3的滤镜filter
(过滤器)
2、语法格式:
filter: 函数(); 例如filter: blur(5px);其中blur函数用于模糊处理,数值越大越模糊
19、计算盒子宽度(calc函数)
1、calc()此CSS函数让你在声明CSS属性值时执行一些计算
括号里面可以进行±*/的运算
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS3属性calc函数</title>
<style>
.father {
width: 300px;
height: 200px;
background-color: pink;
}
.son {
/* !!!!!!需求我们的子盒子宽度永远比父盒子小30像素 !!!!!!*/
width: calc(100% - 30px);
height: 30px;
background-color: skyblue;
}
</style>
</head>
<body>
<!-- 需求我们的子盒子宽度永远比父盒子小30像素 -->
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
20、21、CSS过渡(transition)效果(重点)
语法:(前两个必须,后两个可以省略)
transition: 要过渡的属性 花费时间 运动曲线 何时开始;
①属性:想要变化CSS属性,宽度高度,背景颜色,内外边距都可以,如果想要所有的属性都变化过渡,写一个all即可
②花费时间:单位是 秒(必须写单位) 比如0.5S
③运动曲线:默认为ease(可以省略)
④何时开始:单位是秒(必须写单位)可以设置延迟触发时间 默认是0s(可以省略)
过渡效果的对象:谁要过渡,就给谁加(放在hover里面也可以)
eg:
transition: height .5s ease 1s;
/* 如果想要写多个属性,利用逗号进行分割 */
transition: width .5s, height .5s;
/* 如果想要多个属性都变化,属性写all(推荐)就可以了 */
transition: all 0.5s;
22、过渡练习——进度条案例
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS3过渡练习-进度条</title>
<style>
.bar {
width: 150px;
height: 15px;
border: 1px solid red;
border-radius: 7px;
/* 给个间距会好看一些 */
padding: 1px;
}
.bar_in {
width: 50%;
height: 100%;
background-color: red;
/* 谁做过渡给谁加 */
transition: all .7s;
}
/* 鼠标经过时,进度条变为100% */
.bar:hover .bar_in {
width: 100%;
}
</style>
</head>
<body>
<div class="bar">
<div class="bar_in"></div>
</div>
</body>
</html>
23、广义的H5(了解)
狭义的HTML:相关标签 CSS3:样式
广义的HTML5是HTML5本身+CSS3+JavaScript
这个集合有时称为HTML5和朋友,通常缩写为HTML5,一定是未来的发展趋势