Javascript Reference - HTML DOM Style flexGrow Property








The flexGrow property gets and sets how much the item will grow relative to the rest of the flexible items inside the container.

Browser Support

flexGrow Yes 10 Yes Yes (WebkitFlexGrow) Yes

Syntax

Return the flexGrow property:

var v = object.style.flexGrow 

Set the flexGrow property:

object.style.flexGrow='number|initial|inherit'




Property Values

number
A unitless number to control how the item will grow relative to the rest of the flexible items. Default value is 0.

Technical Details

Default Value: 0
Return Value: A string representing the flex-grow property
CSS Version CSS3

Example

The following code shows how to make a DIV element grow wider.


<!DOCTYPE html>
<html>
<head>
<style> 
#main {<!--  w  w w.j av a 2  s.  co m-->
    width: 350px;
    height: 100px;
    border: 1px solid black;
    display: -webkit-flex; /* Safari */
    display: flex;
}

/* Safari 6.1+ */
#main div:nth-of-type(1) {-webkit-flex-grow: 1;}
#main div:nth-of-type(2) {-webkit-flex-grow: 1;}
#main div:nth-of-type(3) {-webkit-flex-grow: 1;}

/* Standard syntax */
#main div:nth-of-type(1) {flex-grow: 1;}
#main div:nth-of-type(2) {flex-grow: 1;}
#main div:nth-of-type(3) {flex-grow: 1;}
</style>
</head>
<body>

<div id="main">
  <div style="background-color:red;"></div>
  <div style="background-color:blue;" id="myBlueDiv"></div>
  <div style="background-color:yellow;"></div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myBlueDiv").style.WebkitFlexGrow = "3"; // Safari 6.1+
    document.getElementById("myBlueDiv").style.flexGrow = "3";
}
</script>

</body>
</html>

The code above is rendered as follows: