Javascript Reference - HTML DOM Style flexDirection Property








The flexDirection property sets or gets the direction of the flexible items.

Browser Support

flexDirection Yes 10 Yes Yes (WebkitFlexDirection) Yes

Syntax

Return the flexDirection property:

var v = object.style.flexDirection

Set the flexDirection property:

object.style.flexDirection='row|row-reverse|column|column-reverse|initial|inherit'

Property Values

row
Default value. display flexible items horizontally as a row
row-reverse
As row in reverse order
column
display flexible items vertically as a column
column-reverse
As column in reverse order




Technical Details

Default Value: row
Return Value: A string representing the flex-direction property
CSS Version CSS3

Example

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: