Proprietà CSS di ripetizione in background
Esempio
Ripeti un'immagine di sfondo solo verticalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
La background-repeat
proprietà imposta se/come verrà ripetuta un'immagine di sfondo.
Per impostazione predefinita, un'immagine di sfondo viene ripetuta sia verticalmente che orizzontalmente.
Suggerimento: l'immagine di sfondo viene posizionata in base alla proprietà posizione di sfondo . Se non viene specificata alcuna posizione di sfondo, l'immagine viene sempre posizionata nell'angolo in alto a sinistra dell'elemento.
Valore di default: | ripetere |
---|---|
Ereditato: | no |
Animabile: | no. Leggi su animabile |
Versione: | CSS1 |
sintassi JavaScript: | oggetto .style.backgroundRepeat="repeat-x" |
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente la proprietà.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Nota: IE8 e versioni precedenti non supportano più immagini di sfondo su un elemento.
Sintassi CSS
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Valori di proprietà
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 |
Altri esempi
Esempio
Ripeti un'immagine di sfondo sia verticalmente che orizzontalmente (questo è l'impostazione predefinita):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Esempio
Ripeti un'immagine di sfondo solo orizzontalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Esempio
Non ripetere un'immagine di sfondo. L'immagine verrà mostrata una sola volta:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Esempio
Usando background-repeat: spazio e 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;
}
Esempio
Usa diverse proprietà di sfondo per creare un'immagine "eroe":
.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 */
}
Pagine correlate
Tutorial CSS: Sfondo CSS
Riferimento CSS: proprietà posizione di sfondo
Riferimento HTML DOM: proprietà backgroundRepeat