background-image
property repeats an image both horizontally and vertically.
Some images should be repeated only horizontally or vertically, or they will look strange, like this:
body { background-image:url('gradient2.png'); }If the image is repeated only horizontally (
repeat-x
), the background will look better:
body { background-image:url('gradient2.png'); background-repeat:repeat-x; }Background Image—Set
position
and no-repeat
background-repeat
property is to show the image only once:
body { background-image:url('img_tree.png'); background-repeat:no-repeat; }In the example above, the background image is shown in the same place as the text. To change the position of the image, the position of the image is specified by the
background-position
property:
body { background-image:url('img_tree.png'); background-repeat:no-repeat; background-position:top right; }Background—Shorthand Property
background
:
body { background:#ffffff url('img_tree.png') no-repeat top right; }