Latar Belakang Gaya , Properti Posisi
Contoh
Ubah posisi gambar latar:
document.body.style.backgroundPosition = "top right";
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti backgroundPosition menetapkan atau mengembalikan posisi gambar latar dalam sebuah elemen.
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung properti.
Property | |||||
---|---|---|---|---|---|
backgroundPosition | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaksis
Kembalikan properti backgroundPosition:
object.style.backgroundPosition
Setel properti backgroundPosition:
object.style.backgroundPosition = value
Nilai properti
Value | Description |
---|---|
top left top center top right center left center center center right bottom left bottom center bottom right |
If you only specify one keyword, the other value will be "center". |
x% y% | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. |
xpos ypos | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and units |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Detail Teknis
Nilai Bawaan: | 0% 0% |
---|---|
Nilai Kembali: | String, mewakili posisi gambar latar |
Versi CSS | CSS1 |
Lebih Banyak Contoh
Contoh
Ubah posisi gambar latar dalam elemen <div> ke bawah tengah:
document.getElementById("myDiv").style.backgroundPosition = "center bottom";
Contoh
Ubah posisi gambar latar dalam elemen <div> menjadi horizontal 200 piksel dan vertikal 40 piksel:
document.getElementById("myDiv").style.backgroundPosition = "200px 40px";
Contoh
Kembalikan posisi gambar latar dalam elemen <div>:
document.getElementById("myDiv").style.backgroundPosition;
Halaman Terkait
Tutorial CSS: Latar Belakang CSS
Referensi CSS: properti gambar latar belakang
Referensi CSS: properti posisi latar belakang
Referensi DOM HTML: properti latar belakang