Open In App

HTML | DOM Style flexShrink Property

The Style flexShrink property in HTML DOM is used to set how the specific item can be shrink in relation to the remaining flexible items within the container. 

Syntax:



object.style.flexShrink
object.style.flexShrink = "number|initial|inherit"

Property Values:

Example-1: 






<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Style flexShrink Property
    </title>
    <style>
        #Geeks {
            width: 350px;
            height: 100px;
            border: 1px solid #c3c3c3;
            display: flex;
        }
         
        #Geeks div {
            flex-grow: 1;
            flex-shrink: 1;
            flex-basis: 300px;
        }
    </style>
</head>
 
<body>
    <h4>Click the button</h4>
    <button onclick="GFG()">Click Here!
        <br>
    </button>
    <p></p>
    <div id="Geeks">
        <div style="background-color:#64c962;
                    color:white;">
          GeeksForGeeks1
      </div>
        <div style="background-color:#2c932a;
                    color:white;"
             id="Geeks2">
          GeeksForGeeks2
      </div>
    </div>
   
    <script>
        function GFG() {
           
            // Safari 6.1+
            document.getElementById(
              "Geeks2").style.WebkitFlexShrink = "5";
           
            document.getElementById(
              "Geeks2").style.flexShrink = "5";
        }
    </script>
</body>
 
</html>

Output:

  

Example-2: 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Style flexShrink Property
    </title>
    <style>
        #Geeks {
            width: 350px;
            height: 100px;
            border: 1px solid #c3c3c3;
            display: flex;
        }
         
        #Geeks div {
            flex-grow: 1;
            flex-shrink: 1;
            flex-basis: 300px;
        }
    </style>
</head>
 
<body>
    <h3>The flex-shrink Property</h3>
   
    <div id="Geeks">
        <div style="background-color:#44cc3f;">
      </div>
        <div style="background-color:#34a030;">
      </div>
        <div style="background-color:#2c932a;">
      </div>
        <div style="background-color:#267023;">
      </div>
        <div style="background-color:#175415;">
      </div>
    </div>
   
</body>
 
</html>

Output:

  

Supported Browsers: The browser supported by DOM flex-shrink property are listed below:


Article Tags :