Let the blue DIV element shrink five times more than the rest of the flexible items:
document.getElementById("myBlueDiv".style.flexShrink = "5";
Click the button to set the value of the flexShrink property to "5" for the blue div element.
<!DOCTYPE html> <html> <head> <style> #main {// w w w. j a va2 s .c o m width: 350px; height: 100px; border: 1px solid red; display: flex; } #main div { flex-grow: 1; flex-shrink: 1; flex-basis: 300px; } </style> </head> <body> <div id="main"> <div style="background-color:coral;">Red DIV</div> <div style="background-color:lightblue;" id="myBlueDiv">Blue DIV</div> </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myBlueDiv").style.flexShrink = "5"; } </script> </body> </html>
The flexShrink property specifies how the item will shrink relative to the rest of the flexible items inside the same container.
If the element is not a flexible item, the flexShrink property has no effect.
Property Values
Value | Description |
---|---|
number | A number setting how much the item will shrink relative to the rest of the flexible items. Default value is 0 |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The flexShrink property Default Value: 1
The flexShrink property returns a String representing the flex-shrink property of an element.