前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS:linear-gradient()背景颜色线性渐变

CSS:linear-gradient()背景颜色线性渐变

作者头像
江咏之
发布2022-06-16 09:25:18
1.6K0
发布2022-06-16 09:25:18
举报
文章被收录于专栏:技术社区

css语法

代码语言:javascript
复制
background: linear-gradient(direction,color-stop1,color-stop2,...);

direction:用角度值指定渐变的方向(或角度);

color-stop1,color-stop2,...:用于指定渐变的起止颜色

ps:至少需要两种颜色

代码语言:javascript
复制
background: -webkit-linear-gradient(red,yellow,blue);
background: -o-linear-gradient(red,yellow,blue);
background: -moz-linear-gradient(red,yellow,blue); 
background: linear-gradient(red,yellow,blue); 

兼容性

练习

1、background: linear-gradient(to left,#d3959b,#bfe6ba);

to left 设置渐变从右到左,相当于270deg

2、background: linear-gradient(to right,#d3959b,#bfe6ba);

to right设置渐变从左到右,相当于90deg

3、background: linear-gradient(to top,#d3959b,#bfe6ba);

to top 设置渐变从下到上,相当于0deg

4、background: linear-gradient(to bottom,#d3959b,#bfe6ba);
5、background: linear-gradient(to top right,#d3959b,#bfe6ba);

to right top = to top right :从左下角到右上角,对角线角度

6、background: linear-gradient(45deg,#d3959b,#bfe6ba);

和to top right 有细微差别(背景为正方形的时候无差别)

7、background: linear-gradient(45deg,#d3959b 20%,#bfe6ba);

用百分比指定起始颜色的位置,默认值为0%;

8、background: linear-gradient(to right,#feac5e,#c779d0,#4bc0c8);
9、background: linear-gradient(45deg,#feac5e,#c779d0,#4bc0c8);
10、background: linear-gradient(45deg,rgba(254,172,94,0.5),rgba(199,121,208,0.5),rgba(75,192,200,0.5));

rgba使用了0.5的透明度

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • css语法
  • 兼容性
  • 练习
    • 1、background: linear-gradient(to left,#d3959b,#bfe6ba);
      • 2、background: linear-gradient(to right,#d3959b,#bfe6ba);
        • 3、background: linear-gradient(to top,#d3959b,#bfe6ba);
          • 4、background: linear-gradient(to bottom,#d3959b,#bfe6ba);
            • 5、background: linear-gradient(to top right,#d3959b,#bfe6ba);
              • 6、background: linear-gradient(45deg,#d3959b,#bfe6ba);
                • 7、background: linear-gradient(45deg,#d3959b 20%,#bfe6ba);
                  • 8、background: linear-gradient(to right,#feac5e,#c779d0,#4bc0c8);
                    • 9、background: linear-gradient(45deg,#feac5e,#c779d0,#4bc0c8);
                      • 10、background: linear-gradient(45deg,rgba(254,172,94,0.5),rgba(199,121,208,0.5),rgba(75,192,200,0.5));
                      领券
                      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档