Properti lampiran latar belakang CSS
Contoh
Gambar latar yang tidak akan menggulir dengan halaman (diperbaiki):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti background-attachment
mengatur apakah gambar latar belakang bergulir dengan sisa halaman, atau diperbaiki.
Nilai bawaan: | menggulir |
---|---|
Diwarisi: | tidak |
Animasi: | tidak. Baca tentang animasi |
Versi: kapan: | CSS1 |
Sintaks JavaScript: | objek .style.backgroundAttachment="diperbaiki" |
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung properti.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaks CSS
background-attachment: scroll|fixed|local|initial|inherit;
Nilai properti
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 |
Lebih Banyak Contoh
Contoh
Sebuah gambar latar belakang yang akan bergulir dengan halaman (gulir). Ini adalah default:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Contoh
Cara membuat efek gulir paralaks sederhana (membuat ilusi kedalaman 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;
}
Halaman Terkait
Tutorial CSS: Latar Belakang CSS
Referensi DOM HTML: properti backgroundAttachment