Make Money Online!
Hi, I'm Ben and I own Create a Great Website! I'm currently earning well over $1,500 plus per month online in my spare time, and I want to show you how you can do the same.
Fill out the form below and I'll send you my free guide to create a great website and how you can earn money online just like I do! You won't be disappointed.
Make Money Online!
CSS Tutorials :
CSS Background
CSS background properties are used ot define the background effects of an element.
CSS properties used for background effects include:
- background-color - sets the background color of the element
- background-image - sets the background color of an image
- background-repeat - spedified how a background image repeats.
- background-attachment -
- background-position -
Adding Color Elements to Backgrounds
With CSS, changing the background color is not that much different from changing it with regular HTML, where you might type <body bgcolor="#ABD240">. But with CSS you're not limited to changing the color of only the Web page's body or rows and columns in a table, you can set a background color for just about any element you wantThe background-color property specifies the background color of an element.
Note that the color fills the entire background of the element to which it happens to be applied.
The background color of a page is defined in the body selector:
Example
The background color can be specified by:
- name - a color name, like "blue"
- RGB = an RGB value, like "rgb(255,0,0)"
- Hex - a hex value, lik "#ff0066"
In the example below, the h1, p, and div elements have different background colors:
Example
p {background-color:#e0ffee}
div {background-color:#b72424}
Note that another advantage os working with CSS is that you can create styles for elements that appear only within other elements. For example, the headings in the sidebar are currently styled with h3 tags. You can change the style of these tags by limit the change to only effect the h3 tags appearing only withing the sidebar.
In the example above, only the h3 elements within the sidebar have the specified color.
Background Image
Similar to adding color to the background of elements, you can also add images to the background.
The background-image property specifies an image to use as the background of an element. It refers to the location of the image by ading the URL reference to whichever folder contains the background image.
By default, the image is repeated so it covers the entire element.
The background image for a page can be set like this:
Example
Linking to Images;
The link images/greylines.gif is a relative URL. Relative URLs point to a page in your website. When working with CSS, it's important to note that the address is always relative to the location of the style sheet, not the location of the HTML document.
Background Image - Repeat Horizontally or Vertically
By default, the background-image property repeats an image both horizontally and vertically. It will repeat from left to right and top to bottom on the page. You can use the
backround-repeat property to contol how the image repeats, rather than letting it tile across the entire element.
Using CSS, you can have images repeat only horizontally (the X axis) or only vertically (the Y axis), or you can choose to have images not repeat at all.
Some images should be repeated only horzontally or vertically, or they will look very strange and my be distracting to the visitor.
You set an image to repeat only horizontally by using repeat-x property.
Example
{
background-image:url('redgradient2.png');
background-repeat:repeat-x;
}
You set an image to repeat only vertically by using the repeat-y property.
{
background-image:url('redgradient2.png');
background-repeat:repeat-y;
}
Background Image - Set position and no-repeat
When using a background image, use an image that does not disturb the text.
Showing the image only once is specified by the background-norepeat property:
Example
{
background-image"url)'img_auto.png');
background-repeat:no-repeat;
}
In the example above the background image is shown in the same place as the text. We want to change the position of the image, so that it does not disturb the text too much.
The position of the image is specified by the background-postion prpperty:
Example
{
background-image:)'img_auto.png');
background-repeat:no-repeat;
background-position:right top;
}
Background - Shorthand Property
As you can see from the examples above, there are many properties to consider when dealing with backgrounds.
To shorten the code, it is also possible to specify all the properties in one single property. This is called a shorthand property.
The shorthand property for background is simply "background". Instead of using background-color, background-image, background-repeat, background-attachment, and background-position, to specify an element's background, you can just use background. It can be condensed to something like the example below.
Example
The order of When using the shorthand property the order of the property values are:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
It does not matter if one of the property values are missing, as long as the ones that are present are in this order.
Share this Webpage
This site proudly build with Site Build It!





