Visit Mozilla.org

CSS:background

From MDC

« CSS 参考

[编辑] 摘要

background 属性是一个速记属性用来将单个设置的背景属性写在一行。background 可以设置: background-attachment, background-color, background-image, background-position, background-repeat.

  • 初始值: 参阅单个属性。
  • 应用于:所有元素。
  • 继承性: 无
  • 百分数:background-position
  • 媒体: visual
  • 计算值:参阅单个属性。

[编辑] 语法

background: [background-color || background-image ||
    background-repeat || background-attachment ||
    background-position] | inherit]

[编辑]

background-color
参看 background-color.
background-image 
参看 background-image.
background-repeat 
参看 background-repeat.
background-attachment 
参看 background-attachment.
background-position 
参看 background-position.

[编辑] 例子

View Live Examples

body { 
    background: red;
}

.topbanner {
    background: url("topbanner.png") #00D repeat fixed;
}

[编辑] 提示

存在有效声明的情况下,background属性首先将背景设置为初始值,然后设定为声明中指定的值。你不必为每一个属性单独定义,你只对需要更改默认值的属性进行设置。

[编辑] 规范

[编辑] 浏览器兼容性

Browser Lowest Version
Internet Explorer 4
Firefox 1
Netscape 6
Opera 3.5

[编辑] 参阅

background, background-attachment, background-color, background-image, background-position, background-repeat