HTML - DOM Style Object flexShrink Property
HTML DOM Style Object flexShrink property specifies specifies how much item will shrink relative to the rest of flexible items inside the same container.
Syntax
Set the flexShrink property:object.style.flexShrink= "number | initial | inherit";Get the flexShrink property:
object.style.flexShrink;
Property Values
| Value | Description |
|---|---|
| number | It specifies how much item will shrink relative to rest of flexible items. It's default value is 0. |
| initial | It is used to set this property to it's default value. |
| inherit | It is used to inherit the property of it's parent element. |
Return Value
It returns a string value which represents flex shrink property of an element.
Example of HTML DOM Style Object 'flexShrink' Property
The following example makes div element named Random shrink twice relative to other items.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#flex {
width: 500px;
height: 60px;
border: 1px solid black;
display: flex;
}
#flex div {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 300px;
}
</style>
<title>
HTML DOM Style Object flexShrink Property
</title>
</head>
<body>
<p>Click to apply flexShrink property.</p>
<button onclick="fun()">Apply</button>
<br>
<br>
<div id="flex">
<div style="background-color: #04af2f;">Hello</div>
<div style="background-color: aqua;" id="id1">Random</div>
<div style="background-color: yellow;">Text</div>
</div>
<script>
function fun() {
document.getElementById("id1")
.style.flexShrink = "2"
}
</script>
</body>
</html>
Supported Browsers
| Property | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| flexShrink | Yes 29 | Yes 12 | Yes 20 | Yes 9 | Yes 12.1 |
html_dom.htm
Advertisements




