• 【css | linear-gradient】linear-gradient()的用法


    linear-gradient() CSS函数创建一个由两种或多种颜色沿一条直线进行线性过渡的图像,其结果是数据类型的对象,此对象是一种特殊的 数据类型。

    先看一个线上的示例 https://code.juejin.cn/pen/7277486410842996771 

    语法

    1. /* 渐变轴为 45 度,从蓝色渐变到红色 */
    2. linear-gradient(45deg, blue, red);
    3. /* 从右下到左上、从蓝色渐变到红色 */
    4. linear-gradient(to left top, blue, red);
    5. /* 色标:从下到上,从蓝色开始渐变,到高度 40% 位置是绿色渐变开始,最后以红色结束 */
    6. linear-gradient(0deg, blue, green 40%, red);
    7. /* 颜色提示:从左到右的渐变,由红色开始,沿着渐变长度到 10% 的位置,然后在剩余的 90% 长度中变成蓝色 */
    8. linear-gradient(.25turn, red, 10%, blue);
    9. /* 多位置色标:45% 倾斜的渐变,左下半部分为红色,右下半部分为蓝色,中间有一条硬线,在这里渐变由红色转变为蓝色 */
    10. linear-gradient(45deg, red 0 50%, blue 50% 100%);

    图例

     

    渐变线的起始点位置。如果指定了,则包含 to 和两个关键字:一个指定水平位置(left 或 right),另一个指定竖直位置(top 或 bottom)。关键词的先后顺序无影响。如果没有指定,则默认为 to bottom。 to topto bottomto left 和 to right 分别等价于 0deg180deg270deg 和 90deg。其余值会被转换为角度。

     渐变线的方向的角度。0deg 等价于 to top,增加值相当于顺时针旋转。 

    应用

    多网格背景

    1. .block {
    2. width: 100%;
    3. height: 200px;
    4. background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.3) 10%, rgba(0, 0, 0, 0) 10%),
    5. linear-gradient(rgba(0, 0, 0, 0.3) 10%, rgba(0, 0, 0, 0) 10%);
    6. background-size: 30px 30px;
    7. background-color: white;
    8. }

     棋盘背景

    1. .qipan {
    2. width: 100%;
    3. height: 200px;
    4. background-image: linear-gradient(45deg,#ccc 25%,transparent 0),
    5. linear-gradient(45deg,transparent 75%,#ccc 0),
    6. linear-gradient(45deg,#ccc 25%,transparent 0),
    7. linear-gradient(45deg,transparent 75%,#ccc 0);
    8. background-position: 0 0,-15px 15px,15px -15px,30px 30px;
    9. background-size: 30px 30px;
    10. background-color: white;
    11. }

    商品售卖标签

    1. .remai {
    2. position: relative;
    3. width: 200px;
    4. height: 150px;
    5. background-color: #ccc;
    6. }
    7. .remai::after {
    8. content: "这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍这是商品介绍";
    9. display: block;
    10. height: 100%;
    11. width: 100%;
    12. word-wrap: break-word;
    13. overflow: hidden;
    14. }
    15. .remai::before {
    16. content: "";
    17. position: absolute;
    18. display: block;
    19. height: 100%;
    20. width: 100%;
    21. background-image: linear-gradient(135deg,transparent 10%, rgb(122, 24, 24) 10%,rgb(122, 24, 24) 20%, transparent 20%);
    22. }

     参考链接 https://developer.mozilla.org/zh-CN/docs/Web/CSS/gradient/linear-gradient

  • 相关阅读:
    1 如何入门TensorFlow
    【Spring项目中的Service理解】
    Asp.net MVC Api项目搭建
    MySQL 索引
    Modularized Interaction Network for Named Entity Recognition
    vue项目首屏加载优化--gzip
    Centos Docker部署Redis集群三主三从
    【数据结构】单链表
    web前端第三天作业
    联机算法和脱机算法[Alg_001]
  • 原文地址:https://blog.csdn.net/weixin_43340372/article/details/132812578