Vlastnost CSS pozadí
Příklad
Obrázek na pozadí, který se nebude posouvat se stránkou (opraveno):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
Vlastnost background-attachment
nastavuje, zda se obrázek na pozadí posouvá se zbytkem stránky, nebo zda je pevná.
Výchozí hodnota: | svitek |
---|---|
Zděděno: | Ne |
Animovatelné: | Ne. Přečtěte si o tématu Animable |
Verze: | CSS1 |
Syntaxe JavaScriptu: | objekt .style.backgroundAttachment="fixed" |
Podpora prohlížeče
Čísla v tabulce určují první verzi prohlížeče, která plně podporuje vlastnost.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntaxe CSS
background-attachment: scroll|fixed|local|initial|inherit;
Hodnoty vlastností
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 |
Další příklady
Příklad
Obrázek na pozadí, který se bude posouvat se stránkou (posun). Toto je výchozí:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Příklad
Jak vytvořit jednoduchý efekt rolování paralaxy (vytvořit iluzi 3D hloubky):
.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;
}
Související stránky
CSS tutoriál: CSS pozadí
HTML DOM reference: vlastnost backgroundAttachment