HTML5 和 CSS3 提高


一、HTML5 和 CSS3 提高

1. HTML5 的新增特性

请添加图片描述

1.1 HTML5 新增的语义化标签

请添加图片描述
请添加图片描述
Tips:

  • 这种语义化标准主要是针对搜索引擎
  • 这些新标签页面中可以使用多次
  • 在IE9中,需要把这些元素转换为块级元素
  • 其实,我们移动端更喜欢使用这些标签
  • HTML5还增加了很多其他标签,后面再慢慢学

1.2 HTML5 新增的多媒体标签

新增的多媒体标签主要包含两个:

  1. 音频 < audio >
  2. 视频 < video >

使用它们可以很方便的在页面中嵌入音频和视频,而不再去使用 flash 和其他浏览器插件。
HTML5在不使用插件的情况下,也可以原生的支持视频格式文件的播放,当然,支持的格式是有限的。

1.2.1 视频 < video >

当前< video >元素支持三种视频格式:尽量使用mp4格式
请添加图片描述
语法
请添加图片描述
常见属性
请添加图片描述

1.2.2 音频 < audio >

当前 < audio > 元素支持三种音频格式:
请添加图片描述
语法
请添加图片描述
常见属性
请添加图片描述

  • 现在很多浏览器把音频和视频自动播放禁止了

1.2.3 多媒体标签总结

请添加图片描述

1.3 HTML5 新增的 input 类型

请添加图片描述

  • 重点记住:number、tel、search 这三个
<!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>HTML5新增的input表单</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>

请添加图片描述

1.4 HTML5 新增的表单属性

请添加图片描述
请添加图片描述

<!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>HTML5 新增的表单属性</title>
    <style>
        /* 修改placeholder里面字体的颜色 */
        input::placeholder {
            color: pink;
        }
    </style>
</head>

<body>
    <form action="">
        <input type="search" name="search" id="" required="required" placeholder="pink老师" autofocus="autofocus"
            autocomplete="off">
        <input type="file" name="" id="" multiple="multiple">
        <input type="submit" value="提交">
    </form>
</body>

</html>

请添加图片描述

2. CSS3 的新特性

请添加图片描述

2.1 CSS3 新增选择器

CSS3 给我们新增了选择器,可以更加便捷,更加自由的选择目标元素。

  1. 属性选择器
  2. 结构伪类选择器
  3. 伪元素选择器

2.2 属性选择器

请添加图片描述

  • 第二个是重点,必须记住
  • 类选择器、属性选择器和伪类选择器的权重都是10

2.3 结构伪类选择器

请添加图片描述

<!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>CSS新增结构伪类选择器</title>
    <style>
        /* 1. 选择ul里面的第一个孩子 小li */
        ul li:first-child {
            background-color: pink;
        }

        /* 2. 选择ul里面的最后一个孩子 小li */
        ul li:last-child {
            background-color: red;
        }

        /* 3. 选择ul里面的第二个孩子 小li */
        ul li:nth-child(2) {
            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>

在这里插入图片描述
请添加图片描述

<!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>CSS新增结构伪类选择器-nth-child</title>
    <style>
        /* 1. 把所有偶数的孩子选出来 */
        ul li:nth-child(even) {
            background-color: #ccc;
        }

        /* 2. 把所有奇数的孩子选出来 */
        ul li:nth-child(odd) {
            background-color: grey;
        }

        /* 3.nth-child(n) 从0开始 每次加1 往后面计算 这里面必须是n 不能是其他的字母 选择了所有的孩子 */
        .one li:nth-child(n) {
            background-color: pink;
        }

        /* 4.nth-child(2n) 选择了所有偶数的孩子 等价于even */
        .two li:nth-child(2n) {
            background-color: pink;
        }

        /* 5.nth-child(2n+1) 选择了所有奇数的孩子 等价于odd */
        .two li:nth-child(2n+1) {
            background-color: skyblue;
        }

        /* 6. 选择了第3个到最后的孩子 */
        .three li:nth-child(n+3) {
            background-color: skyblue;
        }

        /* 7. 选择了前3个孩子 */
        .four li:nth-child(-n+3) {
            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>
    <ol class="one">
        <li>我是第1个孩子</li>
        <li>我是第2个孩子</li>
        <li>我是第3个孩子</li>
        <li>我是第4个孩子</li>
        <li>我是第5个孩子</li>
        <li>我是第6个孩子</li>
        <li>我是第7个孩子</li>
        <li>我是第8个孩子</li>
    </ol>
    <ol class="two">
        <li>我是第1个孩子</li>
        <li>我是第2个孩子</li>
        <li>我是第3个孩子</li>
        <li>我是第4个孩子</li>
        <li>我是第5个孩子</li>
        <li>我是第6个孩子</li>
        <li>我是第7个孩子</li>
        <li>我是第8个孩子</li>
    </ol>
    <ol class="three">
        <li>我是第1个孩子</li>
        <li>我是第2个孩子</li>
        <li>我是第3个孩子</li>
        <li>我是第4个孩子</li>
        <li>我是第5个孩子</li>
        <li>我是第6个孩子</li>
        <li>我是第7个孩子</li>
        <li>我是第8个孩子</li>
    </ol>
    <ol class="four">
        <li>我是第1个孩子</li>
        <li>我是第2个孩子</li>
        <li>我是第3个孩子</li>
        <li>我是第4个孩子</li>
        <li>我是第5个孩子</li>
        <li>我是第6个孩子</li>
        <li>我是第7个孩子</li>
        <li>我是第8个孩子</li>
    </ol>
</body>

</html>

请添加图片描述
区别:

  1. nth-child 对父元素里面所有孩子排列选择(序号是固定的)先找到第n个孩子,然后再看看是否和E匹配
  2. nth-of-type 对父元素里面指定子元素进行排序选择。先去匹配E,然后再根据E 找到第几个孩子
<!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>CSS3新增nth-of-type选择器</title>
    <style>
        ul li:first-of-type {
            background-color: pink;
        }

        ul li:last-of-type {
            background-color: pink;
        }

        ul li:nth-of-type(even) {
            background-color: skyblue;
        }

        /* :nth-child() 会把所有的盒子排列序号 */
        /* 执行的时候首先看 :nth-child(1) 之后回去看:前面div 不符合就无法实现*/
        section div:nth-child(1) {
            background-color: red;
        }

        /* nth-of-type() 会把指定元素的盒子排列序号 */
        /* 执行的时候首先看:div指定的元素 之后看:nth-of-type(1) 第几个孩子*/
        section div:nth-of-type(1) {
            background-color: blue;
        }
    </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>
    <!-- 区别 -->
    <section>
        <p>光头强</p>
        <div>熊大</div>
        <div>熊二</div>
    </section>
</body>

</html>

在这里插入图片描述
小结
请添加图片描述

2.4 伪元素选择器(重点)

请添加图片描述

<!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>伪元素选择器</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        /* div::before 权重是2 */
        div::before {
            /* 行内元素转换为行内块元素 */
            display: inline-block;
            /* 这个content属性是必须要写的 */
            content: '我';
            width: 50px;
            height: 50px;
            background-color: skyblue;
        }

        div::after {
            content: '小猪佩奇';
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

在这里插入图片描述

2.4.1 使用场景1:伪元素字体图标

请添加图片描述

<!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>伪元素选择器使用场景-字体图标</title>
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?ugft3w');
            src: url('fonts/icomoon.eot?ugft3w#iefix') format('embedded-opentype'),
                url('fonts/icomoon.ttf?ugft3w') format('truetype'),
                url('fonts/icomoon.woff?ugft3w') format('woff'),
                url('fonts/icomoon.svg?ugft3w#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: '\e915';
            color: red;
            font-size: 18px;
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

在这里插入图片描述

2.4.2 使用场景2:仿土豆遮罩效果

<!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>伪元素仿土豆网显示隐藏遮罩案例</title>
    <style>
        .tudou {
            /* 子绝父相 */
            position: relative;
            width: 451px;
            height: 300px;
            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;
        }

        /* 当我们鼠标经过了土豆这个盒子 就让里面的遮罩层显示出来 */
        .tudou:hover::before {
            display: block;
        }
    </style>
</head>

<body>
    <div class="tudou">
        <img src="images/yuyan.jpg" alt="">
    </div>
</body>

</html>

在这里插入图片描述

2.4.3 使用场景3:伪元素清除浮动

之前学过的清除浮动的四个方法:
请添加图片描述
额外标签法
请添加图片描述
父级添加after伪元素
请添加图片描述

  • 只有一个冒号:是因为要照顾I8那些低版本浏览器

父级添加双伪元素
请添加图片描述

2.5 CSS3 盒子模型

请添加图片描述

<!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>CSS3盒子模型</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            border: 20px solid red;
            padding: 15px;
            /* 默认设置 盒子最终的大小为width + padding + border*/
            box-sizing: content-box;
        }

        p {
            width: 200px;
            height: 200px;
            background-color: pink;
            border: 20px solid red;
            padding: 15px;
            /* css3盒子模型 盒子最终的大小就是width 的大小 */
            box-sizing: border-box;
        }
    </style>
</head>

<body>
    <div>
        小猪乔治
    </div>
    <p>
        小猪佩奇
    </p>
</body>

</html>

在这里插入图片描述

2.6 CSS3 其他特性(了解)

  1. 图片变模糊
  2. 计算盒子宽度 width: calc 函数

2.6.1 图片变模糊 CSS3 滤镜filter:

filter CSS属性将模糊或颜色偏移等图形效果应用于元素。
请添加图片描述

<!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>图片模糊处理filter</title>
    <style>
        img {
            /* blur是一个函数 小括号里面数值越大,图片越模糊 注意数值要加px单位 */
            filter: blur(5px);
        }

        img:hover {
            filter: blur(0);
        }
    </style>
</head>

<body>
    <img src="images/pink.jpg" alt="">
</body>

</html>

请添加图片描述

2.6.2 CSS3 calc 函数计算盒子宽度

calc( ) 此CSS函数让你在声明CSS属性值时执行一些计算。
请添加图片描述

<!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>CSS3宽度calc函数</title>
    <style>
        .father {
            width: 300px;
            height: 200px;
            background-color: pink;
        }

        .son {
            /* 算术运算符左右两边必须有空格 */
            width: calc(100% - 30px);
            height: 30px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <!-- 要求:需要我们的子盒子宽度永远比父盒子小30像素 -->
    <div class="father">
        <div class="son"></div>
    </div>
</body>

</html>

请添加图片描述

2.7 CSS3 过渡(重点)

请添加图片描述
请添加图片描述

<!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>CSS3过渡效果(重点)</title>
    <style>
        div {
            width: 200px;
            height: 100px;
            background-color: pink;
            /* transition: 变化的属性 花费时间 移动曲线 何时开始; (后面两个可以省略)*/
            /* 如果想要写多个属性,利用逗号进行分割 */
            /* transition: width 0.5s, height 0.5s; */
            /* 如果想要多个属性都变化,属性写all即可 */
            /* 谁做过渡给谁加 */
            transition: all 0.5s;
        }

        div:hover {
            width: 400px;
            height: 200px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

请添加图片描述

2.7.1 进度条案例

<!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>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 0.7s;
        }

        .bar:hover .bar_in {
            width: 100%;
        }
    </style>
</head>

<body>
    <div class="bar">
        <div class="bar_in"></div>
    </div>
</body>

</html>

请添加图片描述

3. 课后作业

请添加图片描述

3.1 课后作业1-购物格模块

参考文章:https://blog.csdn.net/Cherish_hyx/article/details/110224680

3.1.1 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>课后作业1-购物格模块</title>
    <link rel="stylesheet" href="xm.css">
</head>

<body>
    <div class="father">
        <!--1. 图片模块 -->
        <div class="pic">
            <img src="images/huawei.jpg" alt="">
        </div>
        <!-- 2. 标题 -->
        <p class="text">华为/HUAWEI P50 Pro 骁龙888 4G全网通 原色双影像单元 万象双环设计</p>
        <!-- 3. 价格 -->
        <div class="price">
            <span class="miaosha">¥6988</span>
            <span class="origin">¥6488</span>
        </div>
        <!-- 4. 进度条 -->
        <div class="progressbar">
            <span>已售</span><span class="red">87%</span>
            <div class="bar">
                <div class="bar_in"></div>
            </div>
            <span>剩余</span><span class="red">29</span><span></span>
        </div>
        <!-- 5. 立即抢购链接 -->
        <a href="#">立即抢购</a>
    </div>
</body>

</html>

3.1.2 CSS

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    background-color: #f3f5f7;
}
.father {
    width: 300px;
    height: 470px;
    margin: 100px auto;
    background-color: #fff;
}
/* 1. 图片模块 */
.pic {
    width: 280px;
    height: 280px;
    background-color: skyblue;
    margin: 0 auto;
}
.pic img {
    width: 100%;
    height: 100%;
}
/* 2. 标题 */
.text {
    margin: 10px;
    color: #050505;
}
/* 3. 价格 */
.price,
.progressbar,
a {
    margin: 10px;
}
/* 4. 进度条 */
.miaosha {
    font-size: 20px;
    font-weight: 700;
    color: #e4393c;
}
.origin {
    font-size: 14px;
    color: grey;
    text-decoration: line-through;
}
.bar {
    display: inline-block;
    width: 130px;
    height: 13px;
    border: 1px solid #bd2716;
    border-radius: 10px;
    padding: 0.5px;
}
.bar_in {
    width: 87%;
    height: 100%;
    background-color: red;
    border-radius: 10px;
}
.progressbar span {
    font-size: 14px;
    color: grey;
}
.progressbar .red {
    color: red;
}
/* 5. 立即抢购按钮框 */
a {
    display: block;
    width: 280px;
    height: 50px;
    background-color: #bd2716;
    color: #fff;
    font-size: 20px;
    text-align: center;
    line-height: 50px;
    text-decoration: none;
}

3.1.3 效果图

在这里插入图片描述

3.2 课后作业2-logo过渡切换

参考文章:https://blog.csdn.net/Cherish_hyx/article/details/110245958

<!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>课后作业2-logo过渡切换</title>
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?nwmc59');
            src: url('fonts/icomoon.eot?nwmc59#iefix') format('embedded-opentype'),
                url('fonts/icomoon.ttf?nwmc59') format('truetype'),
                url('fonts/icomoon.woff?nwmc59') format('woff'),
                url('fonts/icomoon.svg?nwmc59#icomoon') format('svg');
            font-weight: normal;
            font-style: normal;
            font-display: block;
        }

        .show {
            position: relative;
            width: 60px;
            height: 60px;
            background-color: #ff6a00;
            margin: 100px auto;
        }

        .box {
            position: absolute;
            left: 5px;
            top: 5px;
            width: 120px;
            height: 60px;
            margin: auto;
            /* background-color: skyblue; */
            transition: all .5s;

        }

        span {
            font-family: 'icomoon';
            font-size: 50px;
            color: #fff;
        }

        .box:hover {
            left: -50px;
        }
    </style>
</head>

<body>
    <div class="show">
        <div class="box">
            <span class="first"></span>
            <span class="second"></span>
        </div>
    </div>
</body>

</html>

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值