Style leftProperty
Style Object
Definition and Usage
The left property sets or returns the left position of a positioned element.
This property specifies the left position of the element, including: padding, scrollbar, border, and margin.
Tip:A positioned element is an element whose position property is set to: relative, absolute, or fixed.
Syntax
Set the left property:
Object.style.left="auto|length|%|inherit"
Return the left property:
Object.style.left
| Value | Description |
|---|---|
| auto | Default. The left position is calculated by the browser. |
| length | Defines the left edge of the element relative to the left edge of the nearest positioned parent element, using units such as px, cm. Negative values are allowed. |
| % | Defines the left edge of the element as a percentage of the left edge of the nearest positioned parent element. |
| inherit | The value of the left property is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the left property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Set the left position of a button:
<html>
<head>
<style type="text/css">
#b1
{
position:absolute;
}
</style>
<script>
function displayResult()
{
document.getElementById("b1").style.left="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Set left position to 100 px">
</body>
</html>
<head>
<style type="text/css">
#b1
{
position:absolute;
}
</style>
<script>
function displayResult()
{
document.getElementById("b1").style.left="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Set left position to 100 px">
</body>
</html>
Try it yourself »
Style Object Other Extensions