HTML DOM Style atas properti
Definisi dan Penggunaan
top set properti atau mengembalikan posisi teratas dari elemen positioning.
Atribut ini menetapkan posisi teratas dari elemen, yang terdiri dari: padding, scroll bar, perbatasan, dan margin.
Tip: elemen positioning adalah atribut posisi elemen diatur: relatif (relative), mutlak (absolut) atau tetap (fixed).
tatabahasa
Mengatur properti atas:
Object.style.top="auto|length|%|inherit"
Kembali properti atas:
Object.style.top
值 | 描述 |
---|---|
auto | 默认。通过浏览器计算顶部的位置。 |
length | 使用 px、cm 等单位定义元素的顶边到最近一个具有定位设置父元素的顶部边缘的位置。可使用负值。 |
% | 定义元素的顶边到最近一个具有定位设置父元素的顶部边缘的百分比位置。 |
inherit | top 属性的值从父元素继承。 |
Dukungan Browser
Semua browser utama mendukung properti atas.
Catatan: IE7 dan versi sebelumnya tidak mendukung "mewarisi" nilai.IE8 hanya menyediakan! DOCTYPE didukung "mewarisi". dukungan IE9 "mewarisi".
contoh
contoh
Pengaturan tombol di posisi teratas:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Jenis Style = "text / css">
# B1 {
position: absolute;
}
</ Style>
<Script>
Fungsi displayResult () {
. Document.getElementById ( "b1") style.top = "100px";
}
</ Script>
</ Kepala>
<Body>
<Input type = "button" id = "b1" onclick = "displayResult ()" value = "diatur ke atas posisi 100 px">
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Jenis Style = "text / css">
# B1 {
position: absolute;
}
</ Style>
<Script>
Fungsi displayResult () {
. Document.getElementById ( "b1") style.top = "100px";
}
</ Script>
</ Kepala>
<Body>
<Input type = "button" id = "b1" onclick = "displayResult ()" value = "diatur ke atas posisi 100 px">
</ Body>
</ Html>
Coba »
gaya Objects