CSS background-allegato Proprietà
Esempio
Un'immagine di sfondo che non scorrerà con la pagina (fissa):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
La background-attachment
proprietà imposta se un'immagine di sfondo scorre con il resto della pagina o è fissa.
Valore di default: | scorrere |
---|---|
Ereditato: | no |
Animabile: | no. Leggi su animabile |
Versione: | CSS1 |
sintassi JavaScript: | oggetto .style.backgroundAttachment="fisso" |
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente la proprietà.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintassi CSS
background-attachment: scroll|fixed|local|initial|inherit;
Valori di proprietà
Value | Description |
---|---|
scroll | The background image will scroll with the page. This is default |
fixed | The background image will not scroll with the page |
local | The background image will scroll with the element's contents |
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
Un'immagine di sfondo che scorrerà con la pagina (scorrimento). Questa è l'impostazione predefinita:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Esempio
Come creare un semplice effetto di scorrimento parallasse (creare un'illusione di profondità 3D):
.fixed-bg {
/* The background image */
background-image: url("img_tree.gif");
/* Set a specified height, or the minimum height for the background image */
min-height: 500px;
/* Set background image to fixed (don't scroll along with the page) */
background-attachment: fixed;
/* Center the background image */
background-position: center;
/* Set the background image to no repeat */
background-repeat: no-repeat;
/* Scale the background image to be as large as possible */
background-size: cover;
}
Pagine correlate
Tutorial CSS: Sfondo CSS
Riferimento DOM HTML: proprietà backgroundAttachment