The flexBasis
property gets and sets the initial length of a flexible item.
flexBasis |
Yes | 10.0 | Yes | Yes (WebkitFlexBasis) | Yes |
Return the flexBasis property:
var v = object.style.flexBasis
Set the flexBasis property:
object.style.flexBasis='number|auto|initial|inherit'
Default Value: | auto |
---|---|
Return Value: | A string representing the flex-basis property |
CSS Version | CSS3 |
The following code shows how to set the initial length of a flex-item to 200 pixels.
<!DOCTYPE html>
<html>
<head>
<style>
#main {<!-- w w w . jav a2 s .c om-->
width: 350px;
height: 100px;
border: 1px solid #c3c3c3;
display: -webkit-flex; /* Safari */
display: flex;
}
#main div {
-webkit-flex-grow: 0; /* Safari 6.1+ */
-webkit-flex-shrink: 0; /* Safari 6.1+ */
-webkit-flex-basis: 40px; /* Safari 6.1+ */
flex-grow: 0;
flex-shrink: 0;
flex-basis: 50px;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:coral;">A</div>
<div style="background-color:lightblue;" id="myDIV">B</div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.WebkitFlexBasis = "200px"; // Safari 6.1+
document.getElementById("myDIV").style.flexBasis = "200px";
}
</script>
</body>
</html>
The code above is rendered as follows: