CSS背景(background)

1.背景颜色

background-color: 颜色值;   默认的值是 transparent  透明的

2.背景图片(image)

语法:
background-image : none | url (url) ;
例如:
background-image: url(images/1.png);

3.背景平铺(repeat)

background-repeat : repeat | no-repeat | repeat-x | repeat-y 
参数作用
repeat背景图像在纵向和横向上平铺(默认的)
no-repeat背景图像不平铺
repeat-x背景图像在横向上平铺
repeat-y

背景图像在纵向平铺  

什么是repeat?
        
什么是repeat-x?
        
什么是repeat-y?
        

4.背景位置(position)

background-position : length || length
background-position : position || position 
参数
length百分数 | 由浮点数字和单位标识符组成的长度值
positiontop | center | bottom | left | center | right   方位名词

注意:

  • 必须先指定background-image属性

  • position 后面是x坐标和y坐标。可以使用方位名词或者 精确单位。

  • 如果指定两个值,两个值都是方位名字,则两个值前后顺序无关,比如left  top和top  left效果一致

  • 如果只指定了一个方位名词,另一个值默认居中对齐。

  • 如果position 后面是精确坐标, 那么第一个,肯定是 x 第二个一定是y

  • 如果只指定一个数值,那该数值一定是x坐标,另一个默认垂直居中

  • 如果指定的两个值是 精确单位和方位名字混合使用,则第一个值是x坐标,第二个值是y坐标

背景简写:

  • background:属性的值的书写顺序官方没有强制的标准。为了可读性,建议如下写:

  • background: 背景颜色 背景图片地址 背景平铺 背景滚动 背景位置;

/* 有背景图片背景颜色可以不用写*/
background: transparent url(image.jpg) repeat-y  scroll center top ;

5.背景图像固定background-attachment

背景是否跟着滚动而滚动

6.背景半透明(CSS3)

background: rgba(0, 0, 0, 0.3);
background: rgba(0, 0, 0, .3);
  • 等同于background-color: rgba(0, 0, 0, .3)

  • 最后一个参数是alpha 透明度  取值范围 0~1之间

  • 我们习惯把0.3 的 0 省略掉  这样写 background: rgba(0, 0, 0, .3);

  • 注意:背景半透明是指盒子背景半透明,盒子里面的内容不受影响

  • 低于IE 9的版本不支持

盒子半透明 opacity

  • 设置opacity元素的所有后代元素会随着一起具有透明性,一般用于调整图片或者模块的整体不透明度

opacity: .2;

7.背景总结

属性作用
background-color背景颜色预定义的颜色值/十六进制/RGB代码
background-image背景图片url(图片路径)
background-repeat是否平铺repeat/no-repeat/repeat-x/repeat-y
background-position背景位置length/position    分别是x  和 y坐标, 切记 如果有 精确数值单位,则必须按照先X 后Y 的写法
background-attachment背景固定还是滚动scroll/fixed
背景简写更简单背景颜色 背景图片地址 背景平铺 背景滚动 背景位置;  他们没有顺序
背景透明让盒子半透明background: rgba(0,0,0,0.3);   后面必须是 4个值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值