HTML DOM Style right Property


The HTML DOM Style right property returns and modify the right position of a positioned HTML element in an HTML document.

Syntax

Following is the syntax −

1. Returning right

object.right

2. Modifying right

object.right = “value”

Here, value can be −

Sr.NoValue & Explanation
1initial
It set this property value to its default value.
2inherit
It inherits this property value from its parent element.
3percentage(%)
It defines value in percentage of the width of the parent element.
4length
It define value right in length unit.
5auto
It lets the browser set the value of right position.

Let us see an example of HTML DOM Style right Property −

Example

Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem 0;
   }
   .square {
      width: 100px;
      height: 100px;
      background: #db133a6b;
      position: relative;
   }
   .show {
      font-size: 1.2rem;
      margin: 1rem 0;
   }
</style>
<body>
<h1>DOM Style right Property Demo</h1>
<div class='square'></div>
<button onclick="set()" class="btn">Set right position</button>
<script>
   function set() {
      document.querySelector('.square').style.right = "-400px";
   }
</script>
</body>
</html>

Output

Click on “Set right position” button to set the right position of pink square.

Updated on: 17-Feb-2021

16 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements