1. Introduction
This subsection is not normative.
When elements are rendered according to the CSS box model [CSS-BOX-3], each element is either not displayed at all, or formatted as one or more rectangular boxes. Each box has a rectangular content area, a band of padding around the content, a border around the padding, and a margin outside the border. (The margin may actually be negative, but margins have no influence on the background and border.)
The properties of this module deal with the decoration of the border area and with the background of the content, padding, and border areas. Additionally the box may be given a “drop-shadow” effect with the box-shadow property.
If an element is broken into multiple box fragments, box-decoration-break [CSS-BREAK-3] defines how the borders and background are divided over the various fragments. (An element can result in more than one fragment if it is broken at the end of a line, at the end of a column or at the end of a page; and continued in the next line, column or page.)
The relative stacking order of backgrounds, borders, and shadows is given in this module. For how these layers interact with other rendered content, see Appendix E “Elaborate description of Stacking Contexts” in [CSS2].
1.1. Module Interactions
This module replaces and extends the background and border features defined in [CSS2] sections 8.5 and 14.2.
All properties in this module apply to the ::first-letter pseudo-element. The background properties and border-radius properties also apply to the ::first-line pseudo-element. The UA may (but is not required to) apply the border-image or box-shadow properties to ::first-line. The UA must not apply the border-color/style/width properties to ::first-line. [CSS2]
1.2. Value Definitions
This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types. For example, combining with CSS Images allows for using CSS gradients as background-image or border-image values. [CSS-IMAGES-3]
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.
2. Backgrounds
Each box has a background layer that may be fully transparent (the default), or filled with a color and/or one or more images. The background properties specify what color (background-color) and images (background-image) to use, and how they are sized, positioned, tiled, etc.
The background properties are not inherited, but the parent box’s background will shine through by default because of the initial transparent value on background-color.
2.1. Layering Multiple Background Images
The background of a box can have multiple background image layers. The number of layers is determined by the number of comma-separated values in the background-image property. Note that a value of none still creates a layer.
Tests
Each of the background images is sized, positioned, and tiled according to the corresponding value in the other background properties. The lists are matched up from the first value: excess values at the end are not used. If a property doesn’t have enough comma-separated values to match the number of layers, the UA must calculate its used value by repeating the list of values until there are enough.
background-image: url(flower.png), url(ball.png), url(grass.png); background-position: center center, 20% 80%, top left, bottom right; background-origin: border-box, content-box; background-repeat: no-repeat;
has exactly the same effect as this set, with the extra position dropped and the missing values for background-origin and background-repeat filled in (emphasized for clarity):
background-image: url(flower.png), url(ball.png), url(grass.png); background-position: center center, 20% 80%, top left; background-origin: border-box, content-box, border-box; background-repeat: no-repeat, no-repeat, no-repeat;
The first image in the list is the layer closest to the user, the next one is painted behind the first, and so on. The background color, if present, is painted below all of the other layers.
Note: The border-image properties can also define a background image, which, if present, is painted on top of the background layers created by the background properties.
2.2. Base Color: the background-color property
Name: | background-color |
---|---|
Value: | <color> |
Initial: | transparent |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Computed value: | computed color |
Canonical order: | per grammar |
Animation type: | by computed value |
Tests
- background-color-animation-backdrop-infinite-duration-crash.html (live test) (source)
- background-color-animation-element-not-visible-at-current-viewport.html (live test) (source)
- background-color-animation-fallback-additive-keyframe.html (live test) (source)
- background-color-animation-fallback-missing-0-percent.html (live test)