CSS设置背景和渐变色

1. 添加背景色

纯色背景:用background-color
渐变背景:用line-gradient,也可以一次用多个

div {
  background-color: red;
}

div {
  /* 单个渐变背景 */
  background: linear-gradient(to bottom, red, green);

  background: linear-gradient(to bottom, red, green 20%, orange 80%, blue);
  /* 多个渐变背景 */
  background: 
        linear-gradient(to bottom, cyan, transparent),
    linear-gradient(225deg, magenta, transparent),
    linear-gradient(45deg, yellow, transparent);
}

效果如下:
请添加图片描述

2. 添加背景图

background属性官网介绍:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background

图片背景:可以合在一起background;也可以单独写每个属性,例如background-clip、background-color、background-image、background-origin、background-position、background-repeat、background-size,和 background-attachment等

渐变背景:linear-gradient

div {
  /* 将背景设为一张居中放大的图片 */
  background: no-repeat center/50% url("../images/icon_test.png");
}
div {
  background-image: linear-gradient(to bottom, red, green 20%, orange 80%, blue);
  background-image: 
        linear-gradient(to bottom, cyan, transparent),
    linear-gradient(225deg, magenta, transparent),
    linear-gradient(45deg, yellow, transparent);
}

效果:
请添加图片描述

3.添加背景图和背景色混合

div {
  /* 中间是图片,四周是背景色 */
  background: url("../images/icon_test.png") center/50% no-repeat, linear-gradient(to bottom, red, green);
  /* 上部分是图片,后面是渐变背景色 */
  background: url("../images/icon_test.png") 0 0 no-repeat, linear-gradient(to right bottom,  red 200px, green);
}

// 我的代码
div {
  background: url('../images/icon_bg.png') 0 0 no-repeat, linear-gradient(to bottom, #FCFDFD, #FCFDFD);
  // background: #FCFDFD url('../images/icon_bg.png') 0 0 no-repeat;
  background-size: 100%;
}

在这里插入图片描述
请添加图片描述

  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值