CSS样式——背景

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position

background-color

opacity 属性指定元素的不透明度/透明度。取值范围为 0.0 - 1.0。值越低,越透明:

div {
  background-color: green;
  opacity: 0.3;
}
div {
  background: rgba(0, 128, 0, 0.3) /* 30% 不透明度的绿色背景 */
}

background-image

指定图片的地址:

body {
  background-image: url("gradient_bg.png");
}

默认情况下,该属性慧在水平方向和竖直方向都会重复图片。可以设置:

background-repeat:no repeat;

或者水平方向和竖直方向 repeat -x,repeat-y.

background-position

定义图片加载的起始位置

(1)名字定义:

  • top left
  • top center
  • top right
  • center left
  • center center
  • center right
  • bottom left
  • bottom center
  • bottom right

(2)%定义

(3)像素定义

background-attachment

fixed   固定位置,滚动不会消失

scroll  随着文本一起滚动。

简写顺序:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
body {
  background: #ffffff url("tree.png") no-repeat right top;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值