The flexDirection
property sets or
gets the direction of the flexible items.
flexDirection |
Yes | 10 | Yes | Yes (WebkitFlexDirection) | Yes |
Return the flexDirection property:
var v = object.style.flexDirection
Set the flexDirection property:
object.style.flexDirection='row|row-reverse|column|column-reverse|initial|inherit'
row
in reverse ordercolumn
in reverse orderDefault Value: | row |
---|---|
Return Value: | A string representing the flex-direction property |
CSS Version | CSS3 |
The following code shows how to rearrange the direction of the flexible items.
<!DOCTYPE html>
<html>
<head>
<style>
#main {<!-- w w w .jav a 2 s.co m-->
width: 350px;
height: 150px;
border: 1px solid black;
display: -webkit-flex; /* Safari */
-webkit-flex-direction: row; /* Safari 6.1+ */
display: flex;
flex-direction: row;
}
#main div {
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:coral;">A</div>
<div style="background-color:yellow;">B</div>
<div style="background-color:red;">C</div>
<div style="background-color:pink;">D</div>
<div style="background-color:blue;">E</div>
<div style="background-color:lightgreen;">F</div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("main").style.WebkitFlexDirection = "column-reverse"; // Safari 6.1+
document.getElementById("main").style.flexDirection = "column-reverse";
}
</script>
</body>
</html>
The code above is rendered as follows: