background-color:颜色值;
rgba(255,255,255,0.3)
这个是设置带透明度的图片。最后一个参数就是透明度,0.3可以简写成.3
- 默认值:
transparent
透明的
背景图片
-
background-img:url(/.);
我们一般装饰的图片都设置成 背景图片,因为位置特别好控制。
url
无需双引号""
引入,默认值是none
-
平铺background-repeat 默认值是平铺的
<style> .box { width: 300px; height: 300px; background-image: url(./img/logo.jpg); } </style> <body> <div class="box">背景图片的默认值是平铺的</div> </body>
参数:
-
repeat 平铺
-
no-repeat 不平铺
-
repeat-x 沿着x轴平铺
-
repeat-y沿着y轴平铺
-
背景定位background-position
backg-position: x y
(x,y 坐标)
参数 :
参数值 | 说明 |
---|---|
长度 | 百分数|由浮点数和单位标识符组成的长度值 |
方位名词 | top|center|bottom|left|center|right |
例如:
background-position:center center;
-
这个
xy
坐标是反过来的 y轴正方向向下 -
注意我们在x y都使用方位名词的时候,顺序是不影响的。
-
如果我们缺省一个参数,但是另一参数一定是center
-
使用精确单位是有顺序要求的,第一个参数一定是 x坐标 第二个一定是y坐标
-
可以混合用,顺要求同上
背景图像固定 (背景附着)
background-attachment:scroll|fixed;
(随着内容滚动|固定)
<style>
body {
height: 6000px;
background-image: url(./img/bc.jpg);
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed; */
background-attachment: scroll;
}
</style>
-
background-attachment:fixed;
背景固定在后面 -
background-attachment:scroll;
背景的混合写法
例如background:#ffffff url('img_tree.png') no-repeat right top;
但是要求遵守如下顺序:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
结语
放假第第7天