CSS_背景
一、背景颜色
background-color设置背景颜色
二、背景图片
background-image:url(“./img/1.png”)
2.1、background-repeat
作用:用来设置背景的重复方式
可选值:
-repeat默认值,背景会沿着x轴y轴双方向重复
-repeat-x沿着x轴方向重复
-repeat-y沿着y轴方向重复
-no-repeat背景图片不重复
2.2、background-position
作用:用来设置背景图片的位置,雪碧图的使用
设置方式:
–通过top left right bottom center 几个表示方位词来设置背景图片的位置
background-position:left
使用方位词时必须要同时指定两个值,如果只写一个则第二个默认为center
--通过偏移量来指定背景图片的位置:
语法:background-position:水平方向的偏移量 垂直方向变量
background-position: -50px 300px
background-position: 50% 30%
2.3、background-clip
设置背景的范围
background-clip
可选值:
–border-box默认值,背景会出现在边框的下边
–padding-box
–背景不会出现在边框,只出现在内容区和内边距
–content-box
–背景只会出现在内容区
2.4、background-origin
background-origin背景图片的偏移量计算的原点
padding-box默认值,background -position从内边距处开始计算
content-box 背景图片的偏移 量从内容区处计算
border-box背景图片的变量从边框处开始计算
2.5、background-size
作用:设置背景图片的大小
第一个值表示宽度
第二个值表示高度
如果只写一个,则第二个值默认是auto
cover图片的比例不变,将元素铺满
contain图片比例不变,将图片在元素中完整显示
background-size:cover;
background-size:contain;
background-size:100% auto;/*不建议使用。会使图片变形*/
2.6、background-attachment
background- attachment
背景图片是否跟随元素移动
可选值:
scroll默认值背景图片会跟随元素移动
fixed背景会固定在页面中,不会随元素移动
背景样式简写属性–直接使用background
backgound背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
并且该样式没有顺序要求,也没有哪个属性是必须写的T
注意:
background-size必须写在background -position的后边,并且使用/隔开
background-position/background-size
background-origin background-clip 两个样式,orgin要在clip的前边
还没有评论,来说两句吧...