使用background和background-color指定背景色之间的区别是什么?
片段# 1
body { background-color: blue; }
段# 2
body { background: blue; }
使用background和background-color指定背景色之间的区别是什么?
片段# 1
body { background-color: blue; }
段# 2
body { background: blue; }
当前回答
Background是以下属性的简写:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
你可以在这里找到每一处房产的详细信息
属性的顺序
在大多数浏览器实现中(我认为可能旧浏览器会出现问题),属性的顺序并不重要,除了:
background-origin and background-clip: when both of this properties are present, the first one refer to -origin and the second to -clip. Example: background: content-box green padding-box; Is equivalent to: background-origin: content-box; background-color: green; background-clip: padding-box; background-size must always follow background-position and the properties must be separated by / if background-position is composed by two numbers, the first one is the horizontal value and the second the vertical value.
其他回答
它们都是一样的。有多个背景选择器(即background-color, background-image, background-position),你可以通过更简单的背景选择器或更具体的背景选择器访问它们。例如:
background: blue url(/myImage.jpg) no-repeat;
or
background-color: blue;
background-image: url(/myImage.jpg);
background-repeat: no-repeat;
使用background,你可以设置所有的背景属性,比如:
背景颜色 背景图像 平铺方式 背景位置 等。
使用background-color,你可以指定背景的颜色
background: url(example.jpg) no-repeat center center #fff;
VS.
background-image: url(example.jpg);
background-position: center center;
background-repeat: no-repeat;
background-color: #fff;
更多信息
(见说明:背景-速记属性)
这是最好的答案。速记(背景)是为了重置和干燥(与手写结合)。
Background是背景颜色和其他一些背景相关的东西的快捷方式,如下所示:
background-color
background-image
background-repeat
background-attachment
background-position
阅读下面来自W3C的声明:
背景-速记属性用于缩短代码 也可以指定所有的背景属性在一个单一 财产。这被称为速记属性。 background的简写属性是background:
body {
background: white url("img_tree.png") no-repeat right top;
}
当使用速记属性时,属性值的顺序是:
背景颜色 背景图像 平铺方式 background-attachment 背景位置 如果缺少一个属性值,这并不重要 其他的都是这个顺序。
Background是以下属性的简写:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
你可以在这里找到每一处房产的详细信息
属性的顺序
在大多数浏览器实现中(我认为可能旧浏览器会出现问题),属性的顺序并不重要,除了:
background-origin and background-clip: when both of this properties are present, the first one refer to -origin and the second to -clip. Example: background: content-box green padding-box; Is equivalent to: background-origin: content-box; background-color: green; background-clip: padding-box; background-size must always follow background-position and the properties must be separated by / if background-position is composed by two numbers, the first one is the horizontal value and the second the vertical value.