In CSS, you can use the background-repeat attribute to prevent the background image from repeating. This attribute can set whether and how the background image is repeated; just set "background-repeat:no-repeat;" to the background image. ” style to prevent the background image from repeating.
The operating environment of this tutorial: Windows 7 system, HTML5&&CSS3 version, Dell G3 computer.
Recommended:css video tutorial
CSS setting background image
In CSS, we You can use the background attribute to set the background image, such as the following code
When we run the code, we find that the background image is repeated whether horizontally or vertically until it covers the entire display area.
CSS background-repeat attribute
There is a background-repeat attribute in CSS that can set images Whether and how the background image is repeated. Its default value is to repeat both horizontally and vertically. If the value of this property is not set, then the background image will be repeated horizontally and vertically like the sample code above, and cover the entire object. displayed area.
It has three values that can be set, as follows, among which the repeat value is the default.
repeat: Default. The background image will repeat vertically and horizontally.
repeat-x : The background image will repeat horizontally.
repeat-y : The background image will repeat vertically.
no-repeat : The background image will be displayed only once.
inherit: Specifies that the setting of the background-repeat attribute should be inherited from the parent element.
css background image only repeats horizontally (horizontally)
CSS code:
body{ background: url('2019062123225How to make the background image not repeat in css'); background-repeat:repeat-x; }
The running result is as shown below, background The images are repeated horizontally
css background image is repeated vertically
CSS code
body{ background: url('2019062123225How to make the background image not repeat in css'); background-repeat:repeat-y; }
Run results As shown below, the background images are repeated vertically
css background images are not repeated
CSS code
body{ background: url('2019062123225How to make the background image not repeat in css'); background-repeat:no-repeat; }
The running result is as shown below. The background image will not be repeated horizontally or vertically. Only one
will be displayed. For more programming-related knowledge, please visit:programming teaching! !
The above is the detailed content of How to make the background image not repeat in css. For more information, please follow other related articles on the PHP Chinese website!