CSS agtergrond-aanhegsel Eiendom
Voorbeeld
'n Agtergrondprent wat nie saam met die bladsy sal blaai nie (reggemaak):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Meer "Probeer dit self" voorbeelde hieronder.
Definisie en gebruik
Die background-attachment
eienskap bepaal of 'n agtergrondprent saam met die res van die bladsy blaai, of vasgestel is.
Standaard waarde: | blaai |
---|---|
Geërf: | geen |
Animateerbaar: | geen. Lees oor animeerbaar |
Weergawe: | CSS1 |
JavaScript-sintaksis: | objek .style.backgroundAttachment="fixed" |
Blaaierondersteuning
Die nommers in die tabel spesifiseer die eerste blaaierweergawe wat die eiendom ten volle ondersteun.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
CSS-sintaksis
background-attachment: scroll|fixed|local|initial|inherit;
Eiendomswaardes
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 voorbeelde
Voorbeeld
'n Agtergrondprent wat saam met die bladsy sal blaai (scroll). Dit is verstek:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Voorbeeld
Hoe om 'n eenvoudige parallaks-rol-effek te skep (skep 'n 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;
}
Verwante bladsye
CSS-tutoriaal: CSS-agtergrond
HTML DOM verwysing: agtergrondAttachment eiendom