DES 250 Digital Media Design II

Images

CSS background-image Property

The background-image property sets one or more background images for an element. As the name suggests the images are placed in the background of an element meaning that you can place content (such as text) on top (within the same element).

By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

You can control the repetition, placement and size of a background-image with additional "background" properties.

CSS code:
body { background-image: url(../images/water-tile.jpg); } <br>
HTML code:
<body><br /> </body>
result in browser:

The background-repeat property:

With the background-repeat property you can have an image repeat wither horizontally only ("repeat-x"), vertically ("repeat-y") or not at all ("no-repeat").

CSS code:
body { <br>    background-image: url(../images/water-tile.jpg);<br>    background-repeat: repeat-x;<br> } <br>

The background-position property:

It sets the starting position of a background image. The default values are "0% 0%" which means the distance from the left side of the browser is 0% and the distance from the top of the browser is 0%;

Other position values are "left top", "left center", "left bottom", "right top", "right center", "right bottom", "center top", "center center", "center bottom".

CSS code:
body { <br>    background-image: url(../images/water-tile.jpg);<br>    background-repeat: no-repeat;<br>    background-position: 50% 10%;<br> } <br>
result in browser:

The background-size property:

Yes, you guessed it: The background-size property specifies the size of the background images. The default value is "auto" which is the size of the actual image (non-scaled).



Values are: