Właściwość załącznika tła CSS
Przykład
Obraz tła, który nie przewija się wraz ze stroną (naprawiony):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Właściwość background-attachment
określa, czy obraz tła przewija się wraz z resztą strony, czy jest stały.
Domyślna wartość: | zwój |
---|---|
Dziedziczny: | nie |
Animowalny: | nie. Przeczytaj o animacji |
Wersja: | CSS1 |
Składnia JavaScript: | obiekt .style.backgroundAttachment="fixed" |
Obsługa przeglądarki
Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje tę właściwość.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Składnia CSS
background-attachment: scroll|fixed|local|initial|inherit;
Wartości nieruchomości
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 |
Więcej przykładów
Przykład
Obraz tła, który będzie przewijał się wraz ze stroną (przewiń). To jest domyślne:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Przykład
Jak stworzyć prosty efekt przewijania paralaksy (stworzyć iluzję głębi 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;
}
Powiązane strony
Samouczek CSS: Tło CSS
Dokumentacja HTML DOM: właściwość backgroundAttachment