HTML DOM left 屬性
定義和用法
left 屬性設置定位元素左外邊距邊界與其包含塊左邊界之間的偏移。
語法:
Object.style.left=auto|%|length
可能的值
值 | 描述 |
---|---|
auto | 默認。通過瀏覽器來計算左側(cè)的位置。 |
% | 設置元素的左邊到最近一個具有定位設置父元素的左邊緣的百分比位置。 |
length | 使用 px、cm 等單位設置元素的左邊到最近一個具有定位設置父元素的左邊緣的位置?墒褂秘撝。 |
提示和注釋
注釋:如果 "position" 屬性的值為 "static",那么設置 "left" 屬性不會產(chǎn)生任何效果。
實例
下面的例子對按鈕的左邊進行設置:
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setLeftEdge()
{
document.getElementById("b1").style.left="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setLeftEdge()"
value="Set left edge to 100 px" />
</body>
</html>