2、渐变渐变

本文详细解读了HTML/CSS中的线性渐变(linear-gradient)功能,包括其基本语法、方向设定、颜色范围以及重复线性渐变的使用示例。通过实例演示,展示了如何创建从一种颜色平滑过渡到多种颜色的视觉效果。
摘要由CSDN通过智能技术生成

从一种颜色到其他颜色的过渡(两种及两种以上颜色)

1)线性渐变 linear-gradient

线型渐变 : 从一个方向到另一个方向的渐变

  • 语法

background: linear-gradient(方向, 颜色1 范围1, 颜色2 范围2,...);
    方向:数值(单位deg)、关键词(left|right   top|bottom)
    颜色:关键词、十六进制色值、rgb(r,g,b)、rgba(r,g,b,a)
    范围:每个颜色结点的显示范围
    取值:
         1.px
         2.百分比
    注意:
    方向:加前缀需要把to去掉,方向是相反的
    默认方向:从上到下
​
​
取值:
​
1、使用起始位置关键字 
​
- to right  方向自左向右
​
- to top  方向自下而上
​
- to bottom 方向自上而下
​
- to left  方向自右而左
​
- to right top  方向朝向右上角
- to right bottom  方向朝向右下角
- to top left 方向朝向左上角
- to left bottom方向朝向左下角
​
​
 2、使用角度
- 0deg 相当于  to top
- 90deg 相当于 to right
​
  • 重复线性渐变

background:repeating-linear-gradient(方向, 颜色1 范围1, 颜色2 范围2,...);
background: repeating-linear-gradient(180deg, red 0%, red 10%, yellow 10%,yellow 20%);
<!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>
        div {
            width: 300px;
            height: 300px;
            margin: 20px;
        }
​
        /*  方向朝向左上角,red--blue渐变 */
        .box1 {
            background: linear-gradient(to top left, red, yellow, green);
        }
​
        /* 线性渐变:
         从45度方向开始:
         0%-20%:纯黄色
         20%-60%:黄色和粉色渐变
         60%-100%:纯粉色 */
​
        .box2 {
            background: -webkit-linear-gradient(45deg, yellow 20%, pink 60%);
            background: -o-linear-gradient(45deg, yellow 20%, pink 60%);
            background: -moz-linear-gradient(45deg, yellow 20%, pink 60%);
            background: -ms-linear-gradient(45deg, yellow 20%, pink 60%);
            background: linear-gradient(45deg, yellow 20%, pink 60%);
        }
​
        /* 范围是百分比 */
        .box3 {
            background: linear-gradient(90deg, yellow 20%, pink 60%);
        }
​
        /* 范围是px */
        .box7 {
            background: linear-gradient(90deg, yellow 20px, pink 60px);
        }
​
        /* 方向:加前缀需要把to去掉,方向是相反的 */
        .box4 {
            background: -webkit-linear-gradient(right, red, yellow, green);
        }
​
        .box5 {
            background: linear-gradient(to right, red, yellow, green);
        }
​
        /* 重复线性渐变 */
        /* 兼容里的写法,先写私有前缀,在写标准的 */
        .box6 {
            background: -webkit-repeating-linear-gradient(top, red 10%, yellow 20%, green 30%);
            background: -moz-repeating-linear-gradient(top, red 10%, yellow 20%, green 30%);
            background: -o-repeating-linear-gradient(top, red 10%, yellow 20%, green 30%);
            background: -ms-repeating-linear-gradient(top, red 10%, yellow 20%, green 30%);
            /* 不加前缀记得加to */
            background: repeating-linear-gradient(to top, red 10%, yellow 20%, green 30%);
        }
    </style>
</head>
​
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    <div class="box5"></div>
    <div class="box6"></div>
    <div class="box7"></div>
</body>
​
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值