Affecting the background of your pages, tables, and even block elements like the paragraph tags is easier than you think when using Cascading Style Sheets. Using CSS, you can:
- set an image as a background to an element
- indicate the tiling position of the background image
- define the location of that image, like a watermark
background-color
usage:
background-color : <color value>;
background-color : rgb(30%,30%,30%);
background-color : transparent;
Setting the color of your background is easy, and with CSS you can now use both hexadecimal values and RGB values. Plus, you can set some elements to have a transparent background color, so that the background will allow other colors to show through. You can set the background-color on most block elements in current browsers.
Before you begin using the following style elements in your documents, you should be aware that while these elements are supposed to work on any block element, current browsers tend to only support them when used on the <body> tag.
background-image
usage:
background-image : (URL);
background-image : (http://www.yoursite.com/image.gif);
Write URL to a specific image to display as the background for your element.
background-attachment
usage:
background-attachment : fixed;
background-attachment : scroll;
If you use a background attachment of fixed, the background image will be held in one place like a watermark. Using the scroll type will set the image to scroll with the rest of the page. This is the default and standard for background images.
This is an element that doesn't work reliably on any tag but the <body> tag. Click this link to see it in action.
background-repeat
usage:
background-repeat : repeat;
background-repeat : inherit;
background-repeat : repeat-x
background-repeat : repeat-y
background-repeat : no-repeat
The default behavior of Web backgrounds is to repeat endlessly. Thus background images often have to be very large to insure that they don't repeat incorrectly on larger monitors. This tag allows you to specify that a background image might repeat only on the x or y axis, or not repeat at all.
This is an element that doesn't work reliably on any tag but the <body> tag. Click this link to see it in action.
background-position
usage:
background-position : value;
Sets the location of the background image with one of these values:
- top
- bottom
- left
- right
- center
- length
- percentage
This element does not yet work reliably in modern browsers, so I will not give an example.
Once you understand all the different CSS elements you can use to affect the background of your pages and elements, you can combine them into one CSS element. The "background" element.
background
usage:
background : color url(URL) attachment position repeat;
Follow the instructions for the above elements to define your backgrounds as you would like them.
Next Page: Box Properties > 1, 2, 3

