css background用法详解

语法:  background:bg-color bg-image bg-position/bg-size bg-repeat bg-origin bg-clip bg-attachment ;

           背景:背景色 背景图 背景图定位/背景图大小 背景图重复 背景图定位位置 绘制区域边缘 是否固定

 

常用举例(缩写版):

background:#fff;
background:url("../img/logo.png");
background:url("../img/logo.png") center top;
background:url("../img/logo.png") 80% 100px;
background:url("../img/logo.png") no-repeat;
background:url("../img/logo.png") left bottom/80px 100% fixed;
background:#fff url("../img/logo.png") center center/80px 100px no-repeat fixed;

bg-position 和 bg-size 可以都写,也可以二选一,都写时要用 / 分隔。

 

bg-position 默认值为  0% 0%  

可选值为:

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

⚠️注意:火狐和欧朋使用该属性时,要设置bg-attachment为fixed

 

bg-size 默认值为 auto 

可选值为:

50px 100px  (只填一个值时默认第二个为auto)

30% 100%  (只填一个值时默认第二个为auto)

100px 50% 或 100% 60px (混合使用)

cover  (完全覆盖,短边为100%)

contain (图被包含,长边为100%)

 

bg-attachment 默认值为 scroll

可选值为scroll  fixed  inherit

 

bg-origin 和 bg-clip 默认值分别为:padding-box 、border-box

bg-origin : 影响bg-position,只改变背景图(只对背景图片起作用)的定位区域。  注意如果背景图像background-attachment是"fixed",这个属性没有任何效果。

bg-clip :内容框相对定位的背景图片 背景覆盖的边缘位置(以 内边框、边框、内容区域 为边缘进行绘制)

它们的可选值都是:border-box   padding-box   content-box

 

参考:http://www.runoob.com/cssref/css3-pr-background.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值