Open In App

HTML | DOM Style objectPosition Property

The DOM Style objectPosition property is used to set or return how an image or video would be positioned in their own content box. 

Syntax:



object.style.objectPosition
object.style.objectPosition = "position|initial|inherit"

Property Values:

Example-1: 






<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Style objectPosition Property
    </title>
    <style>
        .content {
            border: 1px solid;
            object-fit: cover;
            height: 250px;
            width: 500px;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
      GeeksforGeeks
    </h1>
    <b>
      DOM Style objectPosition Property
    </b>
    <p>
      The objectPosition property
      specify how an image or video
      should be positioned in its content box.
    </p>
    <img src=
         height="800"
         width="800"
         class="content" />
   
    <button onclick="setObjectPosition()">
        Change resize
    </button>
 
    <!-- Script to set objectPosition to 50% 100% -->
    <script>
        function setObjectPosition() {
            elem = document.querySelector('.content');
            elem.style.objectPosition = '75% 100%';
        }
    </script>
</body>
 
</html>

Output:

 

Example-2: 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Style objectPosition Property
    </title>
    <style>
        .content {
            border: 1px solid;
            object-fit: cover;
            height: 250px;
            width: 500px;
            object-position: 50% 100%;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
      GeeksforGeeks
    </h1>
    <b>
      DOM Style objectPosition Property
    </b>
    <p>
        The objectPosition property specify
      how an image or video should be
      positioned in its content box.
    </p>
    <img src=
         height="800"
         width="800"
         class="content" />
 
    <button onclick="setObjectPosition()">
        Change resize
    </button>
 
    <!-- Script to set objectPosition to initial -->
    <script>
        function setObjectPosition() {
            elem = document.querySelector('.content');
            elem.style.objectPosition = 'initial';
        }
    </script>
</body>
 
</html>

Output:

 

Example-3: 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Style objectPosition Property
    </title>
    <style>
        #parent {
            object-position: 50% 100%;
        }
         
        .content {
            border: 1px solid;
            object-fit: cover;
            height: 250px;
            width: 500px;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
      GeeksforGeeks
    </h1>
    <b>
      DOM Style objectPosition Property
    </b>
    <p>
        The objectPosition property specify how an
      image or video should be positioned in its content box.
    </p>
    <div id="parent">
        <img src=
             height="800"
             width="800"
             class="content" />
    </div>
 
    <button onclick="setObjectPosition()">
        Change resize
    </button>
 
    <!-- Script to set objectPosition to inherit -->
    <script>
        function setObjectPosition() {
            elem = document.querySelector('.content');
            elem.style.objectPosition = 'inherit';
        }
    </script>
</body>
 
</html>

Output:

 

 

Supported Browsers: The browser supported by objectPosition property are listed below:


Article Tags :