css3背景色渐变属性
描述 (Description)
This property sets the background-color
of an element; it’s good practice to specify a foreground color (color
) at the same time, to ensure that conflicts don’t arise with colors or backgrounds that are defined elsewhere.
此属性设置元素的background-color
; 最好同时指定前景色( color
),以确保不会与其他地方定义的颜色或背景发生冲突。
The background of an element is the area covered by the width
and height
of that element (whether those dimensions are set explicitly, or the content dictates them); it also includes the area covered by padding and borders. A background-color
(or background-image
) that’s applied to an element will appear beneath the foreground content of that element, and the area covered by the padding
and border
properties for the element. This coverage area is evident where an element has transparent
(or dotted
or dashed
) borders, and the background is seen beneath the borders (or between the dots). Note that Internet Explorer versions up to and including 6 don’t support transparent
borders.
元素的背景是该元素的width
和height
覆盖的区域(无论这些尺寸是明确设置的,还是内容决定了它们的大小); 它还包括填充和边框所覆盖的区域。 应用于元素的background-color
(或background-image
)将出现在该元素的前景内容之下,以及该元素的padding
和border
属性覆盖的区域。 该覆盖区域很明显,其中元素具有transparent
(或dotted
或dashed
)边框,并且在边框下方(或点之间)可以看到背景。 请注意,Internet Explorer 6或以下版本不支持transparent
边框。
Some area of the element in question must be visible if the background-color
is to show through. If the element has no intrinsic height (defined either by its content or its dimensions), the background will not be seen. If an element contains only floated children which haven’t been cleared then again the background won’t show, as the element’s height will be zero.
如果要显示background-color
则该元素的某些区域必须可见。 如果该元素没有固有高度(由其内容或尺寸定义),则不会看到背景。 如果一个元素仅包含尚未清除的浮动子元素,则背景不会再次显示,因为该元素的高度将为零。
The background
of an element isn’t inherited by its children as is commonly thought, it’ just that the background
will be visible through the child element’s background as the default value is transparent
.
元素的background
并不像通常认为的那样被其子元素继承,因为默认值是transparent
,因此background
将通过子元素的背景可见。
例 (Example)
This style rule assigns a white background (#fff
) to the element with ID "example"
:
此样式规则将白色背景( #fff
)分配给ID为"example"
的元素:
#example{
background-color: #fff;
}
值 (Value)
color
takes any valid CSS color value or color keyword.
color
采用任何有效CSS颜色值或color关键字。
The keyword transparent
sets the background-color
to be transparent. This value ensures that the content of any element that’s beneath the current element will be visible through the transparent background. The default for background-color
is transparent
, so there is no need to specify this value unless you’re overwriting previous definitions.
关键字“ transparent
将background-color
设置为透明。 此值确保通过透明背景可见当前元素下方任何元素的内容。 background-color
的默认值是transparent
,因此除非您覆盖以前的定义,否则无需指定此值。
Color values can be represented in several different ways in CSS (e.g RGBA color values), and the topic is covered in the CSS Concepts section.
颜色值可以在CSS中以几种不同的方式表示(例如RGBA颜色值),并且CSS概念部分中涵盖了该主题。
翻译自: https://www.sitepoint.com/background-color-css-property/
css3背景色渐变属性