![]() |
Applying Colors with CSS Applying Background Colors Background Positioning. Fixed Backgrounds |
|
Handy
Tip:When
coding CSS, you can use browser safe colors such as black, blue,
green etc, or you can use hexidecimal color codes
Cascading Stylesheets Tutorial #9 That's the example code at work above, applied
only to that paragraph. You can apply a background image to just two words, or
if you want to apply the background image to all of your document, place the code
within the body tag like this
Now here's a great example of positioning and controlling background imagesYou can control how an image behaves, if they should tile or not, and where you want the image positioned. As the example shows, background-repeat: no-repeat: stops the image from tiling. A value of repeat-x makes the image tile horizontally. A value of repeat-y makes the image tile vertically. You can make the image display exactly where you specify behind the element you're applying it to. <STYLE TYPE="text/css"> <!-- H3 { background-position: center top; background-repeat: no-repeat; background-image: url(images/hypermouse.gif) } --> </STYLE> The keywords here are,.... vertical alignment: right, center, left horizontal alignment: top, center and bottom. You can apply all the normal length values of px, percent, etc, which gives you even more control over where you position the image. An example: <STYLE TYPE="text/css"> <!-- H3 { background-position: 35px 75px; background-repeat: no-repeat; background-image: url(images/hypermouse.gif) } --> </STYLE> Shorthand Method of Coding. And another way to set your CSS code is to just use the background tag and include everything you want within like this. <STYLE TYPE="text/css"> <!-- H5{ background: url(images/hypermouse.gif) 99FF99 no-repeat center center } --> </STYLE> This is an example of the above code in action. As you can see I have set the graphic to appear on the left. Some browers will render this differently so play around to get it to suit. This is a really great way to place an image behind a paragraph of text and control everthingto your liking. There is much motre to css than just controlling font types and the favorite no underline on links.As you can see with the code, I have applied a background
image, a background color behind the image, applied the no tiling command and
centered the image vertically and horizontally. This is the best way to code your
backgrounds and is much more browser friendly.
|
Custom Search
|