- HTML中文网
- 联系QQ:88526
- QQ交流群

- 微信公众号

background 属性
含义:
background属性是一个缩写属性,可以在一个声明中设置所有的背景属性。
可以设置的属性分别是:background-color, background-position, background-size, background-repeat, background-origin, background-clip, background-attachment,和background-image.
如果上述的值缺少一个也没关系,比如background:#FF0000 ;是允许的
浏览器支持:
属性 | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|
background | 4.0 | 1.0 | 1.0 | 1.0 | 3.5 |
CSS语法
background:bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
属性值
值 | 说明 | 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 |
实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> div{ width:200px; height: 100px; background: pink url("images/logo.png") no-repeat; } </style> <div></div> </body> </html>
点击 "运行实例" 按钮查看在线实例
效果图:
推荐手册