CSS Background Repeat
web development
Wednesday, 31 March 2021
Hacker
web development
CSS Background Repeat
By default, the CSS background image property repeats an image both sides horizontally and vertically.
CSS Background Repeat |
Some images should be repeated only vertically or horizontally, or they will look strange, like this:
Example
body {
background-image: url("gradient_rc.png");
}
If the image above are repeated only horizontally (background-repeat: repeat-x;), the background will looks better:
Example
body {
background-image: url("gradient_rc.png");
background-repeat: repeat-x;
}
Note: To repeat an image vertically, set background-repeat: repeat-y;
CSS background-repeat: no-repeat
Showing the background image only once is also defined by the background-repeat property:
Example
Show the background image only once:
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
In the example above, the background image is placed in the same place as an text. We want to change the position of the background image, so that it does not disturb the text too much.
CSS background position
The background position property is used to specify the position of the background image.
Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
No comments:
Post a Comment