HTML DOM marginLeft 屬性
定義和用法
marginLeft 屬性設(shè)置元素的左外邊距。
語法:
Object.style.marginLeft=auto|length|%
可能的值:
值 | 描述 |
---|---|
auto | 瀏覽器設(shè)置的左外邊距。 |
length | 定義固定的左外邊距。默認(rèn)值是0。 |
% | 定義基于父對(duì)象總高度的百分比左外邊距。 |
實(shí)例
本例更改了段落的左外邊距:
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginLeft="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change the left margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>