CSS Eigenschaft background-attachment
Beispiel
Ein Hintergrundbild, das nicht mit der Seite scrollt (behoben):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Weitere „Probieren Sie es selbst“-Beispiele weiter unten.
Definition und Verwendung
Die background-attachment
Eigenschaft legt fest, ob ein Hintergrundbild mit dem Rest der Seite scrollt oder fixiert ist.
Standardwert: | scrollen |
---|---|
Vererbt: | Nein |
Animierbar: | Nein. Lesen Sie mehr über animierbare |
Ausführung: | CSS1 |
JavaScript-Syntax: | Objekt .style.backgroundAttachment="behoben" |
Browser-Unterstützung
Die Zahlen in der Tabelle geben die erste Browserversion an, die die Eigenschaft vollständig unterstützt.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
CSS-Syntax
background-attachment: scroll|fixed|local|initial|inherit;
Eigenschaftswerte
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 |
Mehr Beispiele
Beispiel
Ein Hintergrundbild, das mit der Seite scrollt (scroll). Dies ist standardmäßig:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Beispiel
So erstellen Sie einen einfachen Parallax-Scrolling-Effekt (erzeugen Sie eine Illusion von 3D-Tiefe):
.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;
}
Verwandte Seiten
CSS-Tutorial: CSS-Hintergrund
HTML-DOM-Referenz: backgroundAttachment-Eigenschaft