CSS background-repeat Property
Voorbeeld
Herhaal een achtergrondafbeelding alleen verticaal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De background-repeat
eigenschap stelt in of/hoe een achtergrondafbeelding wordt herhaald.
Standaard wordt een achtergrondafbeelding zowel verticaal als horizontaal herhaald.
Tip: De achtergrondafbeelding wordt geplaatst volgens de eigenschap background-position . Als er geen achtergrondpositie is opgegeven, wordt de afbeelding altijd in de linkerbovenhoek van het element geplaatst.
Standaardwaarde: | herhalen |
---|---|
geërfd: | Nee |
Animeerbaar: | Nee. Lees over animeren |
Versie: | CSS1 |
JavaScript-syntaxis: | object .style.backgroundRepeat="repeat-x" |
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de eigenschap volledig ondersteunt.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Opmerking: IE8 en eerder ondersteunen niet meerdere achtergrondafbeeldingen op één element.
CSS-syntaxis
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Eigendomswaarden
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 |
Meer voorbeelden
Voorbeeld
Herhaal een achtergrondafbeelding zowel verticaal als horizontaal (dit is standaard):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Voorbeeld
Herhaal een achtergrondafbeelding alleen horizontaal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Voorbeeld
Herhaal geen achtergrondafbeelding. De afbeelding wordt maar één keer getoond:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Voorbeeld
Gebruik background-repeat: spatie en 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;
}
Voorbeeld
Gebruik verschillende achtergrondeigenschappen om een "held"-afbeelding te maken:
.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 */
}
Gerelateerde pagina's
CSS-zelfstudie: CSS-achtergrond
CSS-referentie: eigenschap background-position
HTML DOM-referentie: backgroundRepeat eigenschap