css背景属性
2017-08-21 本文已影响62人
雅玲哑铃

1、背景色·background-color:属性值可以是任何合法的颜色值
这里我们用到的有: 英语单词16进制rgb()hsl()transparent(透明)
background-color不能继承,其默认值是transparent
2、背景图片:backgroung-image:url(“图片路径”);如果是多个背景图片,用逗号隔开
图片路径可以是相对路径也可以是绝对路径

默认值是none,表示背景上没有放置任何图像
background-image也不能继承。事实上,所有背景属性都不能继承
3、background-repeat :默认值是repeat,平铺,填满整个背景
repeat-x图像只在水平方向上重复

repeat-y图像只在垂直方向上重复,
no-repeat则不允许图像在任何方向上平铺
4、图像在背景中的位置background-position
默认位置在左上角
属性值可以是关键字:top、bottom、left、right和center
长度值:如100px或5cm
百分数值:50%(中间)100%(靠右/下)
比如:background-position:top center;靠上居中

background-position:50%;上下左右居中

等价的关键字:

background-position:center;图片始终显示中部

背景属性连写:
background: background-color background-image background-position background-repeat ;四个属性顺序不作要求
5、背景图片大小background-size:100px;(一般写一个值表示宽高按原比例缩放)
background-size:contain:将图片放大到接触宽高任意一个时的大小

cover:自适应铺满容器
