CSS Eigenschaft background-repeat
Beispiel
Wiederholen Sie ein Hintergrundbild nur vertikal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Weitere „Probieren Sie es selbst“-Beispiele weiter unten.
Definition und Verwendung
Die background-repeat
Eigenschaft legt fest, ob/wie ein Hintergrundbild wiederholt wird.
Standardmäßig wird ein Hintergrundbild sowohl vertikal als auch horizontal wiederholt.
Tipp: Das Hintergrundbild wird entsprechend der Eigenschaft background-position platziert. Wenn keine Hintergrundposition angegeben ist, wird das Bild immer in der oberen linken Ecke des Elements platziert.
Standardwert: | wiederholen |
---|---|
Vererbt: | Nein |
Animierbar: | Nein. Lesen Sie mehr über animierbare |
Ausführung: | CSS1 |
JavaScript-Syntax: | Objekt .style.backgroundRepeat="Wiederholung-x" |
Browser-Unterstützung
Die Zahlen in der Tabelle geben die erste Browserversion an, die die Eigenschaft vollständig unterstützt.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Hinweis: IE8 und frühere Versionen unterstützen nicht mehrere Hintergrundbilder auf einem Element.
CSS-Syntax
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Eigenschaftswerte
Value | Description | Play it |
---|---|---|
repeat | The background image is repeated both vertically and horizontally. The last image will be clipped if it does not fit. This is default | |
repeat-x | The background image is repeated only horizontally | |
repeat-y | The background image is repeated only vertically | |
no-repeat | The background-image is not repeated. The image will only be shown once | |
space | The background-image is repeated as much as possible without clipping. The first and last image is pinned to either side of the element, and whitespace is distributed evenly between the images | |
round | The background-image is repeated and squished or stretched to fill the space (no gaps) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Mehr Beispiele
Beispiel
Wiederholen Sie ein Hintergrundbild sowohl vertikal als auch horizontal (dies ist die Standardeinstellung):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Beispiel
Wiederholen Sie ein Hintergrundbild nur horizontal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Beispiel
Wiederholen Sie kein Hintergrundbild. Das Bild wird nur einmal angezeigt:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Beispiel
Verwendung von background-repeat: space und background-repeat: round:
#example2 {
border: 2px solid black;
padding: 25px;
background: url("w3css.gif");
background-repeat: space;
}
#example3 {
border: 1px solid black;
padding: 25px;
background: url("w3css.gif");
background-repeat: round;
}
Beispiel
Verwenden Sie verschiedene Hintergrundeigenschaften, um ein „Helden“-Bild zu erstellen:
.hero-image {
background-image: url("photographer.jpg"); /* The
image used */
background-color: #cccccc; /* Used if the image is
unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
Verwandte Seiten
CSS-Tutorial: CSS-Hintergrund
CSS-Referenz: Eigenschaft background-position
HTML-DOM-Referenz: backgroundRepeat-Eigenschaft