The flexShrink
property gets and sets
how the item will shrink relative to the rest of the flexible items inside the container.
flexShrink |
Yes | 10 | Yes | Yes (WebkitFlexShrink) | Yes |
Return the flexShrink property:
var v = object.style.flexShrink
Set the flexShrink property:
object.style.flexShrink='number|initial|inherit'
Default Value: | 1 |
---|---|
Return Value: | A string representing the flex-shrink property |
CSS Version | CSS3 |
The following code shows how to place a DIV element shrink.
<!DOCTYPE html>
<html>
<head>
<style>
#main {<!--from w w w . j a v a 2 s.c om-->
width: 350px;
height: 100px;
border: 1px solid blue;
display: -webkit-flex; /* Safari */
display: flex;
}
#main div {
-webkit-flex-grow: 1; /* Safari 6.1+ */
-webkit-flex-shrink: 1; /* Safari 6.1+ */
-webkit-flex-basis: 250px; /* Safari 6.1+ */
flex-grow: 1;
flex-shrink: 1;
flex-basis: 250px;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:red;">Red DIV</div>
<div style="background-color:blue;" id="myBlueDiv">Blue DIV</div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myBlueDiv").style.WebkitFlexShrink = "3"; // Safari 6.1+
document.getElementById("myBlueDiv").style.flexShrink = "3";
}
</script>
</body>
</html>
The code above is rendered as follows: