background可以设置背景样式;颜色背景;图片背景
| 值 | 描述 | CSS |
|---|---|---|
| background-color | 规定要使用的背景颜色。 | 1 |
| background-position | 规定背景图像的位置。 | 1 |
| background-size | 规定背景图片的尺寸。 | 3 |
| background-repeat | 规定如何重复背景图像。 | 1 |
| background-origin | 规定背景图片的定位区域。 | 3 |
| background-clip | 规定背景的绘制区域。 | 3 |
| background-attachment | 规定背景图像是否固定或者随着页面的其余部分滚动。 | 1 |
| background-image | 规定要使用的背景图像。 | 1 |
| inherit | 规定应该从父元素继承 background 属性的设置。 | 1 |
background设置背景颜色
<style>
.div_color {
height: 300px;
width: 300px;
background: cornflowerblue; //设置背景 浅蓝色
}
</style>
<div class="div_color"></div>
background插入图片
<style>
.div_color2 {
height: 300px;
width: 300px;
background: url(http://www.dmoe.cc/random.php); //插入图片地址
background-size: cover; //图片显示方式 自适应
}
</style>
<div class="div_color2"></div>
background复合写法
background:背景颜色 url(背景图片地址) 背景平铺 背景图像滚动 背景图片位置 background:black url(images/smm.jpg) no-repeat fixed center top;