propriedade HTML DOM Estilo marginLeft
estilo Objects
Definição e Uso
marginLeft conjuntos de propriedades ou retorna o elemento na margem esquerda.
gramática
Definindo as propriedades marginLeft:
Object.style.marginLeft="%|length|auto|inherit"
Propriedades volta marginLeft:
Object.style.marginLeft
值 | 描述 |
---|---|
% | 定义基于父元素宽度的百分比左外边距。 |
length | 使用 px、cm 等单位定义左外边距的宽度。 |
auto | 浏览器设定的左外边距。 |
inherit | 左外边距从父元素继承。 |
Suporte a navegadores
Todos os principais navegadores suportam marginLeft propriedade.
Nota: IE7 e versões anteriores não suportam o valor "herdar".IE8 só fornece! DOCTYPE suportado "herdar". suporte IE9 "herdar".
Dicas e Notas
propriedades de margem e propriedades de enchimento são inseridos no espaço em torno do elemento. No entanto, a diferença é, a margem vai ser inserido no espaço em torno do lado de fora da fronteira, o espaço de preenchimento inserções no interior da borda do elemento.
Exemplos
Exemplos
Alterar o elemento div na margem esquerda:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
div{
border: 1px solid #FF0000;
}
</style>
<script>
function changeMargin(){
document.getElementById("ex1").style.marginLeft="100px";
}
function changePadding(){
document.getElementById("ex2").style.paddingLeft="100px";
}
</script>
</head>
<body>
<div id="ex1">这是一些文本。</div>
<br>
<button type="button" onclick="changeMargin()">修改div元素的左部外间距</button>
<br>
<br>
<div id="ex2">这是一些文本。</div>
<br>
<button type="button" onclick="changePadding()">修改div元素的左部内间距</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
div{
border: 1px solid #FF0000;
}
</style>
<script>
function changeMargin(){
document.getElementById("ex1").style.marginLeft="100px";
}
function changePadding(){
document.getElementById("ex2").style.paddingLeft="100px";
}
</script>
</head>
<body>
<div id="ex1">这是一些文本。</div>
<br>
<button type="button" onclick="changeMargin()">修改div元素的左部外间距</button>
<br>
<br>
<div id="ex2">这是一些文本。</div>
<br>
<button type="button" onclick="changePadding()">修改div元素的左部内间距</button>
</body>
</html>
tente »
estilo Objects