CSS background-attachment Property
Voorbeeld
Een achtergrondafbeelding die niet meeschuift met de pagina (vast):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De background-attachment
eigenschap stelt in of een achtergrondafbeelding met de rest van de pagina meeschuift of vast is.
Standaardwaarde: | rol |
---|---|
geërfd: | Nee |
Animeerbaar: | Nee. Lees over animeren |
Versie: | CSS1 |
JavaScript-syntaxis: | object .style.backgroundAttachment="vast" |
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de eigenschap volledig ondersteunt.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
CSS-syntaxis
background-attachment: scroll|fixed|local|initial|inherit;
Eigendomswaarden
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 |
Meer voorbeelden
Voorbeeld
Een achtergrond-afbeelding die mee zal scrollen met de pagina (scroll). Dit is standaard:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Voorbeeld
Hoe een eenvoudig parallax-scrolleffect te creëren (creëer een illusie van 3D-diepte):
.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;
}
Gerelateerde pagina's
CSS-zelfstudie: CSS-achtergrond
HTML DOM-referentie: backgroundAttachment-eigenschap