Suscriber with us



Receive HTML?

Syndicate

CSS Background PDF Print E-mail

The CSS background properties define the background effects of an element.

CSS Background Properties

The CSS background properties allow you to control the background color of an element, set an image as the background, repeat a background image vertically or horizontally, and position an image on a page.

how to set an image as the background?

<!-- created by phpguru.biz -->
body
{
background-image:
url('bgimg.jpg')
}
<!-- created by phpguru.biz -->

how to repeat a background image only vertically?

<!-- created by phpguru.biz -->
body
{
background-image:
url('bgimg.jpg');
background-repeat: repeat-x
}
<!-- created by phpguru.biz -->

how to position an image on the page using pixels?

<!-- created by phpguru.biz -->
body
{
background-image: url('img.gif');
background-repeat: no-repeat;
background-attachment:fixed;
background-position: 30% 20%;
}
<!-- created by phpguru.biz -->

how to use the shorthand property for location all of the background properties in one declaration?

<!-- created by phpguru.biz -->
body
{
background: #00ff00 url('img.gif') no-repeat fixed center;
}
<!-- created by phpguru.biz -->

Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.

PHPGURU: The number in the "PHPGURU" column indicates in which CSS suggestion the property is defined (CSS1 or CSS2).

PropertyDescriptionValuesIEFNPHPGURU

 background

A shorthand property for setting all background properties in one declaration

background-color
background-image
background-repeat background-attachment background-position

 4

 1

 6

 1

 background-attachment

Sets whether a background image is fixed or scrolls with the rest of the page

scroll
fixed

 4

 1

 6

 1

 background-color

Sets the background color of an element

color-rgb
color-hex
color-name
transparent

 4

 1

 4

 1

 background-image

Sets an image as the background

url(URL)
none

 4

 1

 4

 1

 background-position

Sets the starting position of a background image

top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right
x% y%
xpos ypos

 4

 1

 6

 1

 background-repeat

Sets if/how a background image will be repeated

repeat
repeat-x
repeat-y
no-repeat

 4

 1

 4

 1

Examples

Set the background color
This example demonstrates how to set the background color for an element.

Set an image as the background
This example demonstrates how to set an image as the background.

How to repeat a background image
This example demonstrates how to repeat a background image.

How to repeat a background image only vertically
This example demonstrates how to repeat a background image only vertically.

How to repeat a background image only horizontally
This example demonstrates how to repeat a background image only horizontally.

How to display a background image only one time
This example demonstrates how to display a background image only one time

How to place the background image
This example demonstrates how to place the image on the page.

How to position a background image using %
This example demonstrates how to position an image on the page using percent.

How to position a background image using pixels
This example demonstrates how to position an image on the page using pixels.

How to set a fixed background image
This example demonstrates how to set a fixed background image. The image will not scroll with the rest of the page.

All the background properties in one declaration
This example demonstrates how to use the shorthand property for location all of the background properties in one declaration.





Digg!Del.icio.us!Google!Live!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Yahoo!Free social bookmarking plugins and extensions for Joomla! websites!
Last Updated ( Monday, 17 March 2008 )
 
< Prev   Next >

CSS Examples

Examples

Polls

Which is the best Scripting language?