CSS background

css background 定义与用法

背景缩写属性可以在一个声明中设置所有的背景属性。

可以设置的属性分别是:background-color, background-position, background-size, background-repeat, background-origin, background-clip, background-attachment,和background-image.

如果上述值缺少一个,这不要紧,例如background:#FF0000 URL(smiley.gif);是允许的。

默认值: 请参阅单独的属性
继承: no
版本: CSS1+ CSS3中的新的属性
JavaScript 语法: object object.style.background="red url(smiley.gif) top left no-repeat"

 

css background 语法

background: color position size repeat origin clip attachment image;

 

说明 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

 

css background 浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持background属性。

注意IE8和更早版本不支持一个元素多个背景图像。

注意 IE7和更早的版本不支持"继承"的值。 IE8需要定义!DOCTYPE。 IE9支持"继承"。

 

css background 实例

在一个div元素中设置多个背景图像(并指定他们的位置):

body{ 
    background: #00ff00 url('smiley.gif') no-repeat fixed center; 
}

在线运行

 

相关文章

CSS 教程: CSS Background

CSS3 教程: CSS3 Backgrounds