HTML DOM Estilo propriedade top
estilo Objects
Definição e Uso
conjuntos de propriedades superiores ou retorna a posição de topo do elemento de posicionamento.
Este atributo especifica a posição de topo de um elemento, compreendendo: preenchimento, barras de rolagem, bordas e margens.
Dica: um elemento de posicionamento é atributo posição do elemento é definido: relative (relativo) e absoluto (absoluto) ou fixa (fixo).
gramática
Definir propriedades principais:
Object.style.top="auto|length|%|inherit"
Cópia de propriedades superiores:
Object.style.top
值 | 描述 |
---|---|
auto | 默认。通过浏览器计算顶部的位置。 |
length | 使用 px、cm 等单位定义元素的顶边到最近一个具有定位设置父元素的顶部边缘的位置。可使用负值。 |
% | 定义元素的顶边到最近一个具有定位设置父元素的顶部边缘的百分比位置。 |
inherit | top 属性的值从父元素继承。 |
Suporte a navegadores
Todos os principais navegadores suportam propriedade superior.
Nota: IE7 e versões anteriores não suportam o valor "herdar".IE8 só fornece! DOCTYPE suportado "herdar". suporte IE9 "herdar".
Exemplos
Exemplos
botão Configurações na parte superior posições:
<! DOCTYPE html>
<Html>
<Head>
<Charset Meta = "utf-8">
<Title> Este tutorial (w3big.com) </ title>
<Style type = "text / css">
# B1 {
position: absolute;
}
</ Style>
<Script>
displayResult function () {
. Document.getElementById ( "b1") style.top = "100px";
}
</ Script>
</ Head>
<Body>
<Input type = "button" id = "b1" onclick = "displayResult ()" value = "está definido para o topo posição 100 px">
</ Body>
</ Html>
<Html>
<Head>
<Charset Meta = "utf-8">
<Title> Este tutorial (w3big.com) </ title>
<Style type = "text / css">
# B1 {
position: absolute;
}
</ Style>
<Script>
displayResult function () {
. Document.getElementById ( "b1") style.top = "100px";
}
</ Script>
</ Head>
<Body>
<Input type = "button" id = "b1" onclick = "displayResult ()" value = "está definido para o topo posição 100 px">
</ Body>
</ Html>
tente »
estilo Objects