Web开发 -前端部分-CSS3新特性

发布于:2025-02-10 ⋅ 阅读:(55) ⋅ 点赞:(0)

目录

一 CSS概述

二 CSS3私有前缀

三 CSS3的长度单位

四 新增颜色设置

五 新增选择器

六 新增盒子模型属性

1 box-sizing 怪异盒子模型

2 resize 调整盒子大小

3 box-shadow 盒子阴影

4 opacity 盒子不透明度

七 新增背景属性

1 bcakground-origin背景原点

2 background-clip 背景裁剪

3 background-size 背景尺寸

4 background-xxx 复合属性

5 多背景图

八 新增边框属性

1 边框圆角

2 边框外轮廓

九 新增文本属性

1 文本阴影

2 文本换行

​编辑

3 文本溢出

4 文本修饰

​编辑

十 渐变

1 线性渐变

2 径向渐变

3 重复渐变

十一 新增字体属性

1 web字体

2 字体图标

十二 新增2D属性


一 CSS概述

二 CSS3私有前缀

三 CSS3的长度单位

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box1 {
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }

        /* 视口宽度的百分比 viewport width */
        /* 视口高度的百分比 viewport height */

        /* 可以根据视口的变化而变化 */
        .box2 {
            width: 50vw;
            height: 20vh;
            background-color: blue;
        }

        /* vmax 取视口宽度 视口高度 两者之间的较大值作为标准 */
        /* vmin 取视口宽度 视口高度 两者之间的较小值作为标准 */
    </style>
</head>

<body>
    <div class="box1">像素</div>
    <div class="box2">vw和vh</div>

</body>

</html>

图形化展示:

四 新增颜色设置

五 新增选择器

六 新增盒子模型属性

1 box-sizing 怪异盒子模型

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            /* 内容的宽高 */
            width: 200px;
            height: 200px;
            background-color: skyblue;
            padding: 5px;
            border: 5px solid black;
            /* 将宽高改为整体的宽高 */
            box-sizing: border-box;

        }
    </style>
</head>

<body>
    <div class="box1"></div>
</body>

</html>

图形化展示:

2 resize 调整盒子大小

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        
        .box1 {
            width: 200px;
            height: 200px;
            background-color: skyblue;
            overflow: auto;
            /* 水平方向上的长度调节 */
            resize: horizontal;
            /* 垂直方向上的长度调节 */
            resize: vertical;
            /* 两个方向都可以调节 */
            resize: both;

        }
    </style>
</head>

<body>
    <div class="box1"></div>
</body>

</html>

3 box-shadow 盒子阴影

代码实现:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 300px;
            height: 300px;
            background-color: green;
            font-size: 40px;
            margin: 0 auto;
            margin-top: 100px;

            /* 参数:2个 水平 垂直 两个方向上的阴影 */
            box-shadow: 10px 10px;

            /* 参数:3个 水平 垂直 阴影颜色  */
            box-shadow: 10px 10px black;

            /* 参数:3个 水平 垂直 阴影模糊程度  */
            box-shadow: 10px 10px 10px;

            /* 参数:4个 水平 垂直 阴影模糊程度 阴影颜色 */
            box-shadow: 10px 10px 10px orange;

            /* 参数:5个 水平 垂直 阴影模糊程度 阴影外延 阴影颜色 */
            box-shadow: 10px 10px 10px 0px orange;

            /* 参数:6个 水平 垂直 阴影模糊程度 阴影外延 阴影颜色 内阴影*/
            box-shadow: 10px 10px 10px 0px orange inset;

        }
    </style>


</head>

<body>
    <div class="box1">盒子阴影</div>
</body>

</html>

4 opacity 盒子不透明度

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 300px;
            height: 300px;
            background-color: orange;
            font-size: 40px;
            /* 0为完全透明 1为透明 */
            opacity: 0.3;
        }
    </style>

</head>
<body>
    
    <div class="box1">盒子不透明性</div>

</body>
</html>

七 新增背景属性

1 bcakground-origin背景原点

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box1 {
        background-color: skyblue;
        width: 300px;
        height: 300px;
        margin: 0 auto;
        margin-top: 20px;
        padding: 50px;
        border: 50px dashed rgba(255, 0, 0, 0.4);
        font-size: 30px;
        background-image: url(../../HTML/QQ图片20240919174729.jpg);
        background-repeat: no-repeat;
        /* 从哪一个区域开始铺图片 */
        background-origin: padding-box; 

    }
</style>


<body>

    <div class="box1">背景</div>


</body>

</html>

2 background-clip 背景裁剪

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box1 {
        background-color: skyblue;
        width: 300px;
        height: 300px;
        margin: 0 auto;
        margin-top: 20px;
        padding: 50px;
        border: 50px dashed rgba(255, 0, 0, 0.4);
        font-size: 30px;
        background-image: url(../../HTML/QQ图片20240919174729.jpg);
        background-repeat: no-repeat;
        /* 从哪一个区域开始铺图片 */
        background-origin: padding-box; 
        /* 超出这个区域的内容不呈现 */
        background-clip: padding-box;

    }
</style>


<body>

    <div class="box1">背景</div>


</body>

</html>

3 background-size 背景尺寸

代码实现:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 400px;
            height: 400px;
            border: 1px solid black;
            background-image: url(../../HTML/QQ图片20240919174729.jpg);

            background-repeat: no-repeat;
            /* 将图片完整的呈现出来 */
            background-size: contain;

        }
    </style>

</head>

<body>
    <div class="box1">背景属性</div>
</body>

</html>

4 background-xxx 复合属性

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box1 {
        width: 400px;
        height: 400px;
        margin: 0 auto;
        margin-top: 20px;
        padding: 50px;
        border: 50px dashed rgba(255, 0, 0, 0.4);
        font-size: 30px;

        /* background: 背景颜色 背景url 是否重复 位置/大小 原点 裁剪方式; */
        background: skyblue url(../../HTML/QQ图片20240919174729.jpg) no-repeat 10px 10px / 500px 500px border-box content-box;
        background-size: contain;
    }
</style>

<body>

    <div class="box1">背景</div>

</body>

</html>

图形化展示:

5 多背景图

代码实现:

八 新增边框属性

1 边框圆角

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 400px;
            height: 400px;
            border: 2px solid black;
            margin: 0 auto;
            background-color: cadetblue;

            /* 水平居中 */
            text-align: center;
            /* 垂直居中 */
            /* vertical-align: middle; */
            
            /* 参数可以写像素值 也可以写百分比 */
            border-radius: 50px;
            border-radius: 50%;
            /* 参数也可以指定四个角的具体位置 */
            border-top-left-radius: 20px;
            border-top-right-radius: 20px;
            border-bottom-left-radius: 30px;
            border-bottom-right-radius: 30px;
            /* 可以设置椭圆 */
            border-top-left-radius: 100px 50px;
            border-top-right-radius: 100px 50px;
            border-bottom-left-radius: 100px 50px;
            border-bottom-right-radius: 100px 50px;
        }
    </style>
</head>

<body>
    <div>
        <span style="line-height: 400px;">边框圆角</span>
    </div>
</body>

</html>

图形化展示:

2 边框外轮廓

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            height: 400px;
            width: 400px;
            background-color: skyblue;
            height: 400px;
            padding: 10px;
            border: 10px solid black;
            margin: 0 auto;
            margin-top: 100px;
            text-align: center;
            /* 宽度 颜色 实线 */
            outline-offset: 30px;
            outline-color: orange;
            outline-style: solid;
            /* 边框离元素的距离 */
            outline-offset: 30px;
            /* 复合属性 */
            outline: 20px solid orange;
        }

        span {
            color: blue;
            font-size: 40px;
            line-height: 400px;
        }
    </style>

</head>

<body>
    <div><span>边框外轮廓</span>
    </div>

</body>

</html>

图形化展示:

九 新增文本属性

1 文本阴影

代码实现;

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: black
        }

        h1 {
            font-size: 80px;
            text-align: center;
            color: white;
            text-shadow: 2px 2px 30px orange;
            font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
        }
    </style>
</head>

<body>
    <h1>文本阴影-ax</h1>
</body>

</html>

图形化展示:

2 文本换行

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本换行</title>
    <style>
        div {
            font-size: 20px;
            width: 400px;
            height: 400px;
            border: 1px solid black;
            /* 形式 */
            white-space: pre;
            white-space: pre-wrap;
            white-space: pre-line;
            white-space: nowrap;
        }
    </style>
</head>

<body>
    <div>
        键盘敲烂月薪过万,
        键盘落灰狗屎一堆.
        键盘敲烂月薪过万,
        键盘落灰狗屎一堆.
        键盘敲烂月薪过万,
        键盘落灰狗屎一堆.
        键盘敲烂月薪过万,
        键盘落灰狗屎一堆.
        键盘敲烂月薪过万,
        键盘落灰狗屎一堆.
    </div>

</body>

</html>

3 文本溢出

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            width: 400px;
            height: 400px;
            border: 1px solid black;
            font-size: 20px;
            list-style: none;
            padding-left: 0;
            padding: 10px;
        }

        li {
            margin-bottom: 10px;
            white-space: nowrap;

            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <ul>
        <li>床前明月光,疑是地上霜.举头望明月,低头思故乡.</li>
    </ul>
</body>

</html>

图形化展示:

4 文本修饰

十 渐变

1 线性渐变

2 径向渐变

代码实现:

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 250px;
            height: 200px;
            border: 1px solid black;
            float: left;
            margin-left: 20px;
            margin-top: 20px;
            font-size: 15px;
        }

        .box1 {
            background-image: radial-gradient(red, yellow, green);
        }

        .box2 {
            background-image: radial-gradient(at right top, red, yellow, green);
        }

        .box3 {
            background-image: radial-gradient(at 100px 50px, red, yellow, green);
        }

        .box4 {
            background-image: radial-gradient(circle, red, yellow, green);
        }

        .box5 {
            background-image: radial-gradient(200px 200px, red, yellow, green);
        }

        .box6 {
            background-image: radial-gradient(red 50px, yellow 100px, green 150px);
        }

        .box7 {
            background-image: radial-gradient(100px 50px at 150px 150px, red, yellow, green);
        }
    </style>
</head>

<body>
    <div class="box box1">默认情况</div>
    <div class="box box2">通过关键词调整径向渐变圆的圆心</div>
    <div class="box box3">通过像素值调整径向渐变圆的圆心</div>
    <div class="box box4">通过circle关键字调整为正圆</div>
    <div class="box box5">通过像素值调整为正圆</div>
    <div class="box box6">调整径向渐变的区域</div>
    <div class="box box7">综合写法</div>
</body>

</html>

图形化展示:

3 重复渐变

线性渐变是一种在两种或多种颜色之间创建平滑过渡效果的技术,常用于网页设计、图形设计等领域。在线性渐变中,颜色按照一条直线方向逐渐变化。这条直线的方向可以是水平(从左到右)、垂直(从上到下)或者任何角度的方向。

十一 新增字体属性

1 web字体

2 字体图标

代码实现:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>web字体</title>
    <style>
        /* 第一步 */
        @font-face {
            font-family: 'iconfont';
            src: url('./ziti/iconfont.woff2') format('woff2'),
                url('./ziti/iconfont.woff') format('woff'),
                url('./ziti/iconfont.ttf') format('truetype');
        }

        /* 第二步 */
        .iconfont {
            font-family: "iconfont" !important;
            font-size: 160px;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
    </style>
</head>

<body>
    <!-- 第三步 -->
    <span class="iconfont">&#xe890;</span>

</body>

</html>

图形化展示:

代码实现:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>web字体</title>
    <link rel="stylesheet" href="./ziti/iconfont.css">
    <style>
        .iconfont {
            font-size: 100px;
        }
    </style>
</head>

<body>
    <span class="iconfont icon-neirong"></span>

</body>

</html>

CSS

@font-face {
  font-family: "iconfont";
  /* Project id 4818406 */
  src: url('iconfont.woff2?t=1737782289596') format('woff2'),
    url('iconfont.woff?t=1737782289596') format('woff'),
    url('iconfont.ttf?t=1737782289596') format('truetype');
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-neirong:before {
  content: "\e890";
}

图形化展示:

十二 新增2D属性


网站公告

今日签到

点亮在社区的每一天
去签到