六. CSS 样式补充之 font & background

时间:2022-07-28
本文章向大家介绍六. CSS 样式补充之 font & background,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.字体

font-face可以将服务器中的字体直接提供给用户去使用 问题: 1.加载速度 2.版权 3.字体格式

@font-face { 命名一个自己的字体 /* 指定字体的名字 / font-family:'myfont' ; /也可以是电脑自带的字体/ / 服务器中字体的路径 */ src: url('./font/ZCOOLKuaiLe-Regular.ttf') format("truetype");

font-family: myfont; 引用字体

字体相关的样式

  • color 用来设置字体颜色
  • font-size 字体的大小
  • 和font-size相关的单位
    • em 相当于当前元素的一个font-size
    • rem 相对于根元素的一个font-size
  • font-family 字体族(字体的格式) 可选值:
    • serif 衬线字体
    • sans-serif 非衬线字体
    • monospace 等宽字体

    指定字体的类别,浏览器会自动使用该类别下的字体

    • font-family 可以同时指定多个字体,多个字体间使用,隔开 字体生效时优先使用第一个,第一个无法使用则使用第二个 以此类推 Microsoft YaHei,Heiti SC,tahoma,arial,Hiragino Sans GB,"5B8B4F53",sans-serif
<!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>
    <style>

        /* 
        font-face可以将服务器中的字体直接提供给用户去使用 
            问题:
                1.加载速度
                2.版权
                3.字体格式
        
        */
        @font-face {
                /* 指定字体的名字 */
            font-family:'myfont' ;/*也可以是电脑自带的字体*/
            /* 服务器中字体的路径 */
            src: url('./font/ZCOOLKuaiLe-Regular.ttf') format("truetype");
        }

        p{
            /* 
            字体相关的样式 
                color 用来设置字体颜色
                font-size 字体的大小
                    和font-size相关的单位
                    em 相当于当前元素的一个font-size
                    rem 相对于根元素的一个font-size
                font-family 字体族(字体的格式)
                    可选值:
                        serif  衬线字体
                        sans-serif 非衬线字体
                        monospace 等宽字体
                            - 指定字体的类别,浏览器会自动使用该类别下的字体

                    - font-family 可以同时指定多个字体,多个字体间使用,隔开
                        字体生效时优先使用第一个,第一个无法使用则使用第二个 以此类推

                        Microsoft YaHei,Heiti SC,tahoma,arial,Hiragino Sans GB,"5B8B4F53",sans-serif


            */
            color: blue;
            font-size: 40px;

            /* font-family: 'Courier New', Courier, monospace; */
            font-family: myfont;
        }
    </style>
</head>
<body>
    <p>
        今天天气真不错,Hello Hello How are you!
    </p>
</body>
</html>

2.图标字体1

<!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>
    <link rel="stylesheet" href="./fa/css/all.css">
</head>
<body>
    <!-- 
        图标字体(iconfont)
            - 在网页中经常需要使用一些图标,可以通过图片来引入图标
                但是图片大小本身比较大,并且非常的不灵活
            - 所以在使用图标时,我们还可以将图标直接设置为字体,
                然后通过font-face的形式来对字体进行引入
            - 这样我们就可以通过使用字体的形式来使用图标

        fontawesome 使用步骤
            1.下载 https://fontawesome.com/
            2.解压
            3.将css和webfonts移动到项目中
            4.将all.css引入到网页中
            5.使用图标字体
                - 直接通过类名来使用图标字体
                    class="fas fa-bell"
                    class="fab fa-accessible-icon"

     -->
    
    <i class="fas fa-bell" style="font-size:80px; color:red;"></i>
    <i class="fas fa-bell-slash"></i>
    <i class="fab fa-accessible-icon"></i>
    <i class="fas fa-otter" style="font-size: 160px; color:green;"></i>
</body>
</html>

3. 图标字体2

<!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>
    <link rel="stylesheet" href="./fa/css/all.css">
    <style>
        li{
            list-style: none;
        }

        li::before{
            /* 
                通过伪元素来设置图标字体
                    1.找到要设置图标的元素通过before或after选中
                    2.在content中设置字体的编码
                    3.设置字体的样式
                        fab
                        font-family: 'Font Awesome 5 Brands';

                        fas
                        font-family: 'Font Awesome 5 Free';
                        font-weight: 900; 

            */
            content: 'f1b0';
            /* font-family: 'Font Awesome 5 Brands'; */
            font-family: 'Font Awesome 5 Free';
            font-weight: 900; 
            color: blue;
            margin-right: 10px;
        }
    </style>
</head>
<body>

    <!-- <i class="fas fa-cat"></i> -->

    <ul>
        <li>锄禾日当午</li>
        <li>汗滴禾下土</li>
        <li>谁知盘中餐</li>
        <li>粒粒皆辛苦</li>
    </ul>

    <!-- 

        通过实体来使用图标字体:
            &#x图标的编码;
     -->
    <span class="fas">&#xf0f3;</span>
    
</body>
</html>

4. 阿里的字体库

<!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>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    <style>
        i.iconfont{
            font-size: 100px;
        }

        p::before{
            content: 'e625';
            font-family: 'iconfont';
            font-size: 100px;
        }
    </style>
</head>
<body>

    <i class="iconfont">&#xe61c;</i>
    <i class="iconfont">&#xe622;</i>
    <i class="iconfont">&#xe623;</i>

    <i class="iconfont icon-qitalaji"></i>

    <p>Hello</p>
</body>
</html>

5.行高

行高指的是文字占有的实际高度

可以通过line-height来设置行高

行高可以直接指定一个大小(px em) 也可以直接为行高设置一个整数

如果是一个整数的话,行高将会是字体的指定的倍数

<!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>
    <style>
        div{
            font-size: 50px;

            /* 可以将行高设置为和高度一样的值,使单行文字在一个元素中垂直居中 */
            line-height: 200px;

            /* 
                行高(line height)
                    - 行高指的是文字占有的实际高度
                    - 可以通过line-height来设置行高
                        行高可以直接指定一个大小(px em)
                        也可以直接为行高设置一个整数
                            如果是一个整数的话,行高将会是字体的指定的倍数
                    - 行高经常还用来设置文字的行间距
                        行间距 = 行高 - 字体大小

                字体框
                    - 字体框就是字体存在的格子,设置font-size实际上就是在设置字体框的高度

                行高会在字体框的上下平均分配

            */

            border: 1px red solid;

            /* line-height: 1.33; */
            /* line-height: 1; */
            /* line-height: 10 */
        }
    </style>
</head>
<body>
    
    <div>今天天气这不错 Hello hello 今天天气这不错 Hello hello 今天天气这不错 Hello hello 今天天气这不错 Hello hello</div>

</body>
</html>

6.字体的简写属性

font 可以设置字体相关的所有属性

语法:

font: 字体大小/行高 字体族 (字体大小 字体族 必须写,并写字体族在最后)

行高 可以省略不写 如果不写使用默认值

<!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>
    <style>
        div{
            border: 1px red solid;


            /* 
                font 可以设置字体相关的所有属性
                    语法:
                        font: 字体大小/行高 字体族
                        行高 可以省略不写 如果不写使用默认值
            
            */

            /* font-size: 50px;
            font-family: 'Times New Roman', Times, serif; */
            font-weight: bold;
            /* font: 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            /* font: normal normal 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            font: bold italic 50px/2  微软雅黑, 'Times New Roman', Times, serif;
            /* font:50px 'Times New Roman', Times, serif;
            line-height: 2; */

            /* font-size: 50px; */

            /* font-weight 字重 字体的加粗 
                可选值:
                    normal 默认值 不加粗
                    bold 加粗
                    100-900 九个级别(没什么用)

                font-style 字体的风格
                    normal 正常的
                    italic 斜体
            */
            /* font-weight: bold; */
            /* font-weight: 500;
            font-style: italic; */



        }
    </style>
</head>
<body>
    
    <div>今天天气真不错 Hello hello</div>
    
</body>
</html>

7. 文本的样式1

7.1 水平对齐

text-align 文本的水平对齐

可选值:

  • baseline 默认值 基线对齐
  • top 顶部对齐
  • bottom 底部对齐
  • middle 居中对齐

7.2 垂直对齐

vertical-align 设置元素垂直对齐的方式 可选值:

  • baseline 默认值 基线对齐
  • top 顶部对齐
  • bottom 底部对齐
  • middle 居中对齐
<!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>
    <style>
        div{
            width: 800px;
            border: 1px red solid;

            /* 
                text-align 文本的水平对齐
                    可选值:
                        left 左侧对齐
                        right 右对齐
                        center 居中对齐
                        justify 两端对齐
            */
            /* text-align: justify; */

            font-size: 50px;
        }

        span{
            font-size: 20px;
            border: 1px blue solid;

                /*
                vertical-align 设置元素垂直对齐的方式
                    可选值:
                        baseline 默认值 基线对齐
                        top 顶部对齐
                        bottom 底部对齐
                        middle 居中对齐
                */
            vertical-align:baseline; 
        }

        p{
            border: 1px red solid;

        }

        img{
            vertical-align: bottom;
        }
    </style>
</head>
<body>
    
<div>
    今天天气 Helloyx<span>真不错 Hello</span>!
</div>

    <!-- <div>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illo nihil iure at ab atque nostrum molestiae totam porro, dolorem maiores repudiandae molestias veritatis, eligendi laudantium incidunt dolores corporis? Quibusdam, consequatur.
    </div> -->


    <p>
       <img src="./img/an.jpg" alt=""> 
    </p>

</body>
</html>

8. 文本样式2

8.1 text-decoration 设置文本修饰

可选值:

  • none 什么都没有
  • underline 下划线
  • line-through 删除线
  • overline 上划线

8.2 white-space 设置网页如何处理空白

可选值:

  • normal 正常
  • nowrap 不换行
  • pre 保留空白(网页文件中写的什么样,就是什么样)

8.3 文本溢出的效果设置

text-overflow: ellipsis; 省略号

<!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>
    <style>
        .box1{
            font-size: 50px;
            font-family: 微软雅黑;


            /* 
                text-decoration 设置文本修饰
                    可选值:
                        none 什么都没有
                        underline 下划线
                        line-through 删除线
                        overline 上划线
            */

            /* text-decoration: overline; */

            /* text-decoration: underline red dotted; */
        }

        .box2{
            width: 200px;
            /* 
                white-space 设置网页如何处理空白
                    可选值:
                        normal 正常
                        nowrap 不换行
                        pre 保留空白

            */
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>

    <div class="box2">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur, minus fugit in perspiciatis reprehenderit consequuntur aspernatur repellat cumque quidem asperiores quaerat placeat, tenetur vel veritatis deserunt numquam. Dolores, cupiditate enim.
    </div>

    <div class="box1">
        今天天气真不错
    </div>
</body>
</html>

9. 背景1

9.1 设置背景颜色

background-color 设置背景颜色

9.2 设置背景图片

background-image: url("./img/1.png");设置背景图片

  • 可以同时设置背景图片和背景颜色,这样背景颜色将会成为图片的背景色
  • 如果背景的图片小于元素,则背景图片会自动在元素中平铺将元素铺满
  • 如果背景的图片大于元素,将会一个部分背景无法完全显示
  • 如果背景图片和元素一样大,则会直接正常显示

9.3 设置背景的重复方式

background-repeat 用来设置背景的重复方式

  • repeat 默认值 , 背景会沿着x轴 y轴双方向重复
  • repeat-x 沿着x轴方向重复
  • repeat-y 沿着y轴方向重复
  • no-repeat 背景图片不重复

9.4 设置背景图片的位置

background-position 用来设置背景图片的位置

设置方式:

  • 1.通过 top left right bottom center 几个表示方位的词来设置背景图片的位置
  • 2.使用方位词时必须要同时指定两个值,如果只写一个则第二个默认就是center
  • 3.通过偏移量来指定背景图片的位置:
    • 水平方向的偏移量
    • 垂直方向变量
<!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>

    <style>
        .box1{
            width: 500px;
            height: 500px;
            /* 
                background-color 设置背景颜色
             */
            background-color: #bfa;

            /* 
                background-image 设置背景图片 
                    - 可以同时设置背景图片和背景颜色,这样背景颜色将会成为图片的背景色
                    - 如果背景的图片小于元素,则背景图片会自动在元素中平铺将元素铺满
                    - 如果背景的图片大于元素,将会一个部分背景无法完全显示
                    - 如果背景图片和元素一样大,则会直接正常显示
                    
            */
            background-image: url("./img/1.png");

            /* 
                background-repeat 用来设置背景的重复方式
                    可选值:
                        repeat 默认值 , 背景会沿着x轴 y轴双方向重复
                        repeat-x 沿着x轴方向重复
                        repeat-y 沿着y轴方向重复
                        no-repeat 背景图片不重复
             */
            background-repeat: no-repeat;

            /*
                background-position 用来设置背景图片的位置
                    设置方式:
                        通过 top left right bottom center 几个表示方位的词来设置背景图片的位置
                            使用方位词时必须要同时指定两个值,如果只写一个则第二个默认就是center

                        通过偏移量来指定背景图片的位置:
                            水平方向的偏移量 垂直方向变量
            */
            /* background-position: center; */
            background-position: -50px 300px;



        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

10 背景2

10.1 背景的范围

  • 1.background-clip 可选值:
    • border-box 默认值,背景会出现在边框的下边
    • padding-box 背景不会出现在边框,只出现在内容区和内边距
    • content-box 背景只会出现在内容区
    1. background-origin 背景图片的偏移量计算的原点
    • padding-box 默认值,background-position从内边距处开始计算
    • content-box 背景图片的偏移量从内容区处计算
    • border-box 背景图片的变量从边框处开始计算

10.2 设置背景图片的大小 background-size

第一个值表示宽度 第二个值表示高度(也可以写 %值)

  • 如果只写一个,则第二个值默认是 auto
  • cover 图片的比例不变,将元素铺满 contain 图片比例不变,将图片在元素中完整显示

10.3 背景图片是否跟随元素移动 background-attachment

  • scroll 默认值 背景图片会跟随元素移动
  • fixed 背景会固定在页面中,不会随元素移动

10.4 背景的简写形式

​ background-color ​ background-image ​ background-repeat ​ background-position ​ background-size ​ background-origin ​ background-clip ​ background-attachment - backgound 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置 并且该样式没有顺序要求,也没有哪个属性是必须写的 注意: background-size必须写在background-position的后边,并且使用/隔开 background-position/background-size background-origin background-clip 两个样式 ,orgin要在clip的前边

<!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>

    <style>
        .box1{
            width: 500px;
            height: 500px;
            overflow: auto;
            background-color: #bfa;
            background-image: url("./img/2.jpg");
            background-repeat: no-repeat;
            background-position: 0 0;
            padding: 10px;

            /*
                 设置背景的范围 
                    background-clip 
                        可选值:
                            border-box 默认值,背景会出现在边框的下边
                            padding-box 背景不会出现在边框,只出现在内容区和内边距
                            content-box 背景只会出现在内容区

                    background-origin 背景图片的偏移量计算的原点
                            padding-box 默认值,background-position从内边距处开始计算
                            content-box 背景图片的偏移量从内容区处计算
                            border-box 背景图片的变量从边框处开始计算
            */
            /* background-origin: border-box;
            background-clip: content-box; */

            /* 
                background-size 设置背景图片的大小
                    第一个值表示宽度 
                    第二个值表示高度
                    - 如果只写一个,则第二个值默认是 auto

                    cover 图片的比例不变,将元素铺满
                    contain 图片比例不变,将图片在元素中完整显示
            */
            background-size: contain;

            /* 
                background-color
                background-image
                background-repeat
                background-position
                background-size
                background-origin
                background-clip
                background-attachment

                - backgound 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
                    并且该样式没有顺序要求,也没有哪个属性是必须写的

                    注意:
                        background-size必须写在background-position的后边,并且使用/隔开
                            background-position/background-size

                        background-origin background-clip 两个样式 ,orgin要在clip的前边
                

            
             */




        }

        .box2{
            width: 300px;
            height: 1000px;
            background-image: url('./img/1.png');
            background-repeat: no-repeat;
            background-position: 100px 100px;

            /* 
            background-attachment
                - 背景图片是否跟随元素移动
                - 可选值:
                    scroll 默认值 背景图片会跟随元素移动
                    fixed 背景会固定在页面中,不会随元素移动
             */
            background-attachment: fixed;
        }

        .box3{
            border: 10px red double;
            padding: 50px;
            width: 500px;
            height: 500px;
            background: url('./img/2.jpg') #bfa  center center/contain border-box content-box no-repeat ;
        }

    </style>
</head>
<body>
    <div class="box3">

    </div>
    <!-- <div class="box1">
        <div class="box2">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam aut, odio iusto accusantium ipsum aliquid omnis facere sapiente, nobis vel dicta alias ducimus. Repellat similique unde eius tempore, quia quo.
            Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium, accusamus quibusdam. Adipisci in dolorem qui accusantium accusamus voluptatibus magnam nesciunt minus enim quaerat! Quidem, rem. Ipsum amet praesentium enim aliquid!
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam provident repellendus ipsum dolorum optio quo, iure eveniet beatae cupiditate rerum minus corporis illum aliquam illo ut quidem aliquid expedita deserunt.
        </div>
    </div> -->
</body>
</html>

10.5 背景图片练习 按钮1

<!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>
    <style>
        a:link{
            display: block;
            width: 93px;
            height: 29px;
            background-image: url('./img/08/link.png')
        }

        a:hover{
            background-image: url('./img/08/hover.png')
        }

        a:active{
            background-image: url('./img/08/active.png')
        }

        /*
            图片属于网页中的外部资源,外部资源都需要浏览器单独发送请求加载,
                浏览器加载外部资源时是按需加载的,用则加载,不用则不加载
                像我们上边的练习link会首先加载,而hover和active会在指定状态触发时才会加载

                
          */


    </style>
</head>
<body>

    <a href="javascript:;"></a>
    
</body>
</html>

10.6 背景图片练习 按钮2

<!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>
    <style>
        a:link{
            display: block;
            width: 93px;
            height: 29px;
            background-image: url('./img/09/btn.png')
        }

        a:hover{
            background-position: -93px 0;
        }

        a:active{
            background-position: -186px 0;
        }

/* 
        解决图片闪烁的问题:
            可以将多个小图片统一保存到一个大图片中,然后通过调整background-position来显示的图片
            这样图片会同时加载到网页中 就可以有效的避免出现闪烁的问题
            这个技术在网页中应用十分广泛,被称为CSS-Sprite,这种图我们称为雪碧图

        雪碧图的使用步骤:
            1.先确定要使用的图标
            2.测量图标的大小
            3.根据测量结果创建一个元素
            4.将雪碧图设置为元素的背景图片
            5.设置一个偏移量以显示正确的图片

        雪碧图的特点:
            一次性将多个图片加载进页面,降低请求的次数,加快访问速度,提升用户的体验
 */
        
        .box1{
            width: 128px;
            height: 46px;
            background-image: url('./img/09/amazon-sprite_.png');
            background-position:0 0;
        }

        .box2{
            width: 42px;
            height: 30px;
            background-image: url('./img/09/amazon-sprite_.png');
            background-position: -58px -338px;
        }
    </style>
</head>
<body>

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

    <a href="javascript:;"></a>
    
</body>
</html>

11. 渐变

<!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>
    <style>
        .box1{
            width: 200px;
            height: 200px;
            /* background-color: #bfa; */
            /* 
                通过渐变可以设置一些复杂的背景颜色,可以实现从一个颜色向其他颜色过渡的效果
                !!渐变是图片,需要通过background-image来设置

                线性渐变,颜色沿着一条直线发生变化
                    linear-gradient()

                    linear-gradient(red,yellow) 红色在开头,黄色在结尾,中间是过渡区域
                    - 线性渐变的开头,我们可以指定一个渐变的方向
                        to left
                        to right
                        to bottom
                        to top
                        deg deg表示度数
                        turn 表示圈

                    - 渐变可以同时指定多个颜色,多个颜色默认情况下平均分布,
                        也可以手动指定渐变的分布情况

                    repeating-linear-gradient() 可以平铺的线性渐变
             */
            
            /* background-image: linear-gradient(red,yellow,#bfa,orange); */
            /* background-image: linear-gradient(red 50px,yellow 100px, green 120px, orange 200px); */
            background-image: repeating-linear-gradient(to right ,red, yellow 50px);
            /* 50px 代表最纯颜色的开始的位置 */

        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

12.径向渐变

<!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>
    <style>
        .box1{
            width: 300px;
            height: 300px;

/* 
            radial-gradient() 径向渐变(放射性的效果) */
            /* 
                 默认情况下径向渐变的形状根据元素的形状来计算的
                    正方形 --> 圆形
                    长方形 --> 椭圆形
                    - 我们也可以手动指定径向渐变的大小
                    circle
                    ellipse

                    - 也可以指定渐变的位置
                    - 语法:
                        radial-gradient(大小 at 位置, 颜色 位置 ,颜色 位置 ,颜色 位置)
                            大小:
                                circle 圆形
                                ellipse 椭圆
                                closest-side 近边 
                                closest-corner 近角
                                farthest-side 远边
                                farthest-corner 远角

                            位置:
                                top right left center bottom
                                


             */

            background-image: radial-gradient(farthest-corner at 100px 100px, red , #bfa)
        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>