background property
Specifies up to five separate background properties, in a shorthand form.
With this property, you can set the background color and / or image of any visible HTML element.
Furthermore, you can set how the background image is displayed. You have control over how the background image behaves if the
contents of the element are scrolled (stays in a fixed position, or scrolls with the contents, as it normally does). You can also set
how the image should be repeated (repeats vertically, horizontally, both, or in neither direction).
These features can also be set with five different style properties, listed below.
The use of separate properties is highly recommended for non advanced authors for better controllability.
JavaScript page for this property: background. You can find other example(s) there. |
Possible values:
One of the following values: | ||||||||||||||||
|
Description of values:
Specifies whether the background-image should scroll with the contents of the object or not. | |||||||
Specifies the color to use for the background of the object. | |||||||
Specifies the image to use as the background of the object. | |||||||
Sets the position of the background-image within the element. | |||||||
Specifies how to tile the background-image relative to the upper-left corner of the container object. | |||||||
Takes the value of this property from the computed style of the parent element. |
Default: transparent none repeat scroll 0% 0%.
Example HTML code 1:
This example illustrates the use of the background property:
|
||||
<head> <style> .example1 { background: #F9F9F9 url("picture.gif") no-repeat center bottom; width: 300px; height: 120px; } .example2 { background-color: #F9F9F9; background-image: url("picture.gif"); background-repeat: no-repeat; background-position: center bottom; width: 300px; height: 120px; } </style> </head> <body> <div class="example1">The background image is at the center bottom of this division.</div> <div class="example2">This is the same, but without shorthand background property.</div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example shows how to create a gradient background. First you need to create an image in a painting program. In most cases, the image can be very slim (it may even be 1 pixel wide).
|
||||
<head> <style> .gradient { background-image: url("gradient.gif"); background-repeat: repeat-x; } </style> </head> <body> <div class="gradient"> Division element with <br /> gradient background. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by tags:
a, abbr, acronym, address, b, bdo, big, blink, blockQuote, body, button, caption, center, cite, code, col, colGroup, dd, del, dfn, dir, div, dl, dt, em, fieldSet, font, form, frame, frameSet, H1, H2, H3, H4, H5, H6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isIndex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, optGroup, option, p, plainText, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tr, tt, u, ul, var, xmp
Related pages:
background-attachment
background-color
background-image
background-position
background-position-x
background-position-y
background-repeat
background-color
background-image
background-position
background-position-x
background-position-y
background-repeat
External links:
background (MSDN)
background (Mozilla Developer Center)
background (Safari Reference Library)
background (W3C)
background (Mozilla Developer Center)
background (Safari Reference Library)
background (W3C)
User Contributed Comments