HTML5基础加强css样式篇(background-image线性渐变函数:linear-gradient)(四十)

1.linear-gradient基础:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 200px 0 0 200px;
            width: 200px;
            height: 200px;
            background-color: orange;

            /*基本用法*/
            background-image: linear-gradient(red, yellow, blue, green);
            background-image: linear-gradient(rgba(255, 0, 0, .2), yellow, blue, green);

            /*控制颜色渐变的方向

                to right -- 从左向右
                to top -- 从下到上
                to left -- 从右到左
                to bottom --- 从上到下(默认值)

            */
            background-image: linear-gradient(to right, red, yellow, blue, green);
            background-image: linear-gradient(to top, red, yellow, blue, green);
            background-image: linear-gradient(to left, red, yellow, blue, green);
            background-image: linear-gradient(to bottom, red, yellow, blue, green);


            /*0deg = to top -- 从下到上*/
            background-image: linear-gradient(0deg, red, yellow, blue, green);
            /*基于0度顺时针旋转45deg*/
            background-image: linear-gradient(45deg, red, yellow, blue, green);
            /*基于0度逆时针旋转45deg*/
            background-image: linear-gradient(-45deg, red, yellow, blue, green);


            /*设置过渡颜色的起始位置*/
            /*从过渡起始位置50px开始让红色和黄色之间产生颜色渐变效果*/
            background-image: linear-gradient(to right, red 50px, yellow, blue, green);
            background-image: linear-gradient(to right, red 50px, yellow 50px, blue, green);
            background-image: linear-gradient(to right, red 50px, yellow 50px, yellow 100px, blue, green);



        }

        .box:hover {

        }
    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

2.重复线性渐变:repeating-linear-gradient

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 200px 0 0 200px;
            width: 1200px;
            height: 200px;
            background-color: orange;
    
            background-image: linear-gradient(to right
            , red 0
            , red 50px
            , yellow 50px
            , yellow 100px
            , red 100px
            , red 150px
            , yellow 150px
            , yellow 200px);
            /**与上面重复写渐变有相同的效果*/
            background-image: repeating-linear-gradient(
                    to right
                    , red 0
                    , red 50px
                    , yellow 50px
                    , yellow 100px
            );



        }

        .box:hover {

        }
    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

3.记事本制作:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 0 auto;
            width: 800px;
            height: 500px;
            background-color: orange;
            border: 1px solid;

            background-image: repeating-linear-gradient(
                     #fff 0
                    , #fff 50px
                    , #999 50px
                    , #999 51px
            );
        }

        .box:hover {

        }
    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>
效果:

4.帆布背景制作:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 0 auto;
            width: 800px;
            height: 500px;
            /*background-color: orange;*/
            border: 1px solid;

            background-image: repeating-linear-gradient(
                     rgba(255, 0, 0, .3) 0
                    ,  rgba(255, 0, 0, .3) 20px
                    , rgba(255, 255, 0, .3)  20px
                    , rgba(255, 255, 0, .3)  40px
            ), repeating-linear-gradient( to right,
                    rgba(255, 0, 0, .3) 0
                    ,  rgba(255, 0, 0, .3) 20px
                    , rgba(255, 255, 0, .3)  20px
                    , rgba(255, 255, 0, .3)  40px
            );


            background-image: repeating-linear-gradient(45deg,
                    rgba(255, 0, 0, .3) 0
                    ,  rgba(255, 0, 0, .3) 20px
                    , rgba(255, 255, 0, .3)  20px
                    , rgba(255, 255, 0, .3)  40px
            ), repeating-linear-gradient( -45deg,
                    rgba(255, 0, 0, .3) 0
                    ,  rgba(255, 0, 0, .3) 20px
                    , rgba(255, 255, 0, .3)  20px
                    , rgba(255, 255, 0, .3)  40px
            );



        }

        .box:hover {

        }
    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

效果如下:


5.进度条效果:原理重复线性渐变,移动背景图.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            margin: 100px 0 0 100px;
            width: 800px;
            height: 80px;

            /*渐变图形的大小*/
            background-image: repeating-linear-gradient(
                45deg,
                green 0px,
                green 10px,
                #fff 10px,
                #fff 20px
            );

            background-size: 12000px 80px;
        }

        /*鼠标悬浮,改变背景图位置*/
        .box:hover{
            background-position: -500px 0;
            transition: 10s;
        }


    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

效果:



  • 14
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鸭蛋炒饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值