Free Guides
Language Tutorials

CSS ( Cascading Style Sheet )
Backgrounds
There are 5 background properties, and 1 shorthand.
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
- background (shorthand)
The nice thing about backgrounds is that it doesn't have to apply to the whole screen, as the normal background HTML tag does. To apply a background to the whole page, you use it in the body tag.
You can specify backgrounds in paragraphs, table cells, headers and almost anything else you want.
background-color and
background-image
These two are very straight forward. For background-color the valid
values are colors, be it rgb, hex, or color name, and transparent,
which makes the background transparent.
There are only two values for background-image, none and a url to
point to an image object.
Examples:
color: #FFFFFF; /* color the text white */ }
P.bg2 { background-image: url(images/bg1.gif) }
click here for a not so pretty
example Use better
judgment than I did with this example, but you can see what it can
do.
background-repeat
Valid values are: repeat, repeat-x, repeat-y, and no-repeat. A value
of repeat, repeats the background horizontally and vertically.
repeat-x only repeats the background in the horizontal direction,
repeat-y vertical direction. And as you might have thought no-repeat
does not repeat the background at all.
background-attachment
There are two values for background-attachment, scroll and fixed. A
valid you of scroll is what is common with browsers today. The
background scrolls along as you do. A value of fixed will keep the
background fixed, with the text and other goodies scrolling on top
of it.
background-position
You can specify where the background is to be placed with this
property. Valid values are: length, percentage, top, center, bottom,
left, right.
For example you have a table cell which is bigger than the background image, and you want it to be in the bottom right corner of that cell. Here's the code:
Both of these will do the same thing, you can also position the backgrounds by specifying the pixels offset of the image.
background (shorthand)
The shorthand notation for background follows the order:
background-color, background-image, background-repeat,
background-attachment, and background-position
Example: