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