Properti atas gaya
Contoh
Setel posisi teratas elemen <button>:
document.getElementById("myBtn").style.top = "100px";
Definisi dan Penggunaan
Properti top menetapkan atau mengembalikan posisi teratas dari elemen yang diposisikan.
Properti ini menentukan posisi teratas elemen termasuk padding, scrollbar, border dan margin.
Tip: Elemen yang diposisikan adalah elemen dengan properti posisi disetel ke: relatif, absolut, atau tetap.
Tip: Untuk mengatur atau mengembalikan posisi bawah dari elemen yang diposisikan, gunakan properti bawah .
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
top | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Kembalikan properti teratas:
object.style.top
Setel properti teratas:
object.style.top = "auto|length|%|initial|inherit"
Nilai properti
Value | Description |
---|---|
auto | Lets the browser set the top position. This is default |
length | Defines the top position in length units. Negative values are allowed |
% | Sets the top position in % of the height of the parent element |
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: | mobil |
---|---|
Nilai Kembali: | Sebuah String, mewakili posisi teratas dari elemen yang diposisikan |
Versi CSS | CSS2 |
Lebih Banyak Contoh
Contoh
Menggunakan nilai negatif - Setel posisi teratas elemen <div>:
document.getElementById("myDiv").style.top = "-100px";
Contoh
Kembalikan posisi teratas elemen <div>:
alert(document.getElementById("myDiv").style.top);
Halaman Terkait
Tutorial CSS: Pemosisian CSS
Referensi CSS: properti teratas
Objek Gaya