Javascript DOM CSS Style right Property

Introduction

Set the right position of a <div> element:

document.getElementById("myDIV").style.right = "100px";

Click the button to position the DIV element 100 pixels from the right edge:

If the position property is set to "static", the right property has no effect.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//from ww w  . j av a2 s.  c om
  position: absolute;
  background-color: coral;
  color: white;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <h1>myDIV</h1>
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.right = "100px";
}
</script>

</body>
</html>

The right property sets or gets the right position of a positioned element.

A positioned element is an element with the position property set to: relative, absolute, or fixed.

Property Values

Value Description
autoLets the browser set the right position. default
length Sets the right position in length units. Negative values are allowed
% Sets the right position in % of the width of the parent element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The right property return a String representing the right position of a positioned element.




PreviousNext

Related