Propriété CSS background-attachment
Exemple
Une image de fond qui ne défilera pas avec la page (fixe) :
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La background-attachment
propriété définit si une image d'arrière-plan défile avec le reste de la page ou est fixe.
Valeur par défaut: | faire défiler |
---|---|
Hérité: | non |
Animable : | non. En savoir plus sur l'animation |
Version: | CSS1 |
Syntaxe JavaScript : | objet .style.backgroundAttachment="fixe" |
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la propriété.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntaxe CSS
background-attachment: scroll|fixed|local|initial|inherit;
Valeurs de propriété
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 |
Plus d'exemples
Exemple
Une image de fond qui défilera avec la page (scroll). C'est par défaut :
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Exemple
Comment créer un simple effet de défilement de parallaxe (créer une illusion de profondeur 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;
}
Pages connexes
Tutoriel CSS : Arrière-plan CSS
Référence HTML DOM : propriété backgroundAttachment