css背景属性用法详解

本文详细介绍了CSS3中新增的背景属性,包括background-origin、background-clip、background-attachment等,以及如何综合使用这些属性来实现复杂的背景效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

css3背景
新增的属性:
  • background-origin(指定背景图像的位置区域)padding-box border-box content-box 
  • background-clip(规定背景的绘制区域)border-box  padding-box   content-box
  • background-attachment(设置背景图像是否固定或者随着页面的其余部分滚动)scroll  fixed  inherit
  • background-size: (属性定义了背景图的尺寸)   length   |    percentage   |   cover   |  contain;
  • background-blend-mode(属性定义了背景层的混合模式(图片与颜色)



.d1 {
/* 同时设置两张背景图 */
width: 200px;
height: 200px;
background: linear-gradient(red, pink);                            /* 渐变色*/
background-image: url('1.png'), url('2.jpg');                    /* 图片路径 */
background-position: right bottom, left top;                  /* 图片位置 */
background-repeat: no-repeat, no-repeat;                    /* 是否重复 */
background-size: 200px 100px, 200px 100px;              /* 图片尺寸  ength  %比  cover contain */
background-origin: content-box, content-box;           /* 指定背景图像的位置区域 padding-box border-box content-box 新增属性*/
background-clip: border-box, border-box;                /* 规定背景的绘制区域 border-box|padding-box|content-box */
background-attachment: fixed, fixed;                        /* background-attachment设置背景图像是否固定或者随着页面的其余部分滚动。scroll fixed inherit */
background-blend-mode: normal;                           /* background-blend-mode 属性定义了背景层的混合模式(图片与颜色)。 */
}


综合写法:

.div2{
width: 200px;
height: 200px;
background: url(1.png) right bottom no-repeat, url(2.jpg) left top no-repeat;
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值