Open In App

CSS flex-flow Property

Last Updated : 26 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The flex-flow property is a sub-property of the flexible box layout module and also a shorthand property for flex-wrap and flex-direction.

Note:

The flex property is useless when the element is not a flexible item.

Syntax:

flex-flow: flex-direction flex-wrap;

Values of flex-flow property:

row nowrap: It arranges the row the same as the text direction and the default value of wrap-flex is nowrap. It is used to specify that the item has no wrap. It makes item wrap in single lines. Syntax:

flex-flow: row nowrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row nowrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:row nowrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

row-reverse nowrap: It arrange the row opposite of text direction and the default value of wrap-flex is nowrap. It is used to specify that the item has no wrap. It makes item wrap in single lines. Syntax:

flex-flow: row-reverse nowrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row-reverse nowrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:row-reverse nowrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

column nowrap: same as row but top to bottom and the default value of wrap-flex is nowrap. It is used to specify that the item has no wrap. It makes item wrap in single lines. Syntax:

flex-flow: column nowrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column nowrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column nowrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

column-reverse nowrap: Same as row-reverse top to bottom and the default value of wrap-flex is nowrap. It is used to specify that the item has no wrap. It makes item wrap in single lines. Syntax:

flex-flow: column-reverse nowrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column-reverse nowrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column-reverse nowrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

row wrap: It arrange the row same as text direction and wrap property is used to break the flex item into multiples lines. It makes flex items wrap to multiple lines according to flex item width Syntax:

flex-flow: row wrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row wrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:row wrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

row-reverse wrap: It arrange the row opposite of text direction and wrap property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow: row-reverse wrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row-reverse wrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:row-reverse wrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

column wrap: It arrange the row same as row but top to bottom and wrap property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:column wrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column wrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column wrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

column-reverse wrap: It arrange the row same as row-reverse top to bottom. and wrap property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:column-reverse wrap; 
Example: html
<!DOCTYPE html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column-reverse wrap;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column-reverse wrap</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

row wrap-reverse: It arrange the row same as text direction and wrap-reverse property This property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:row wrap-reverse; 
Example: html
<!DOCTYPE html>
<html>
<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row wrap-reverse;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow: row wrap-reverse</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>
</html>
Output:

row-reverse wrap-reverse: It arrange the row opposite text direction and wrap-reverse property This property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:row-reverse wrap-reverse; 
Example: html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: row-reverse wrap-reverse;
        }
        #main div {
            width: 100px;
            height: 50px;
        }
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow: row-reverse wrap-reverse</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>
</html>
Output:

column wrap-reverse: It arrange the row same as row but top to bottom.and wrap-reverse property This property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:column wrap-reverse; 
Example: html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column wrap-reverse;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column wrap-reverse</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>
</html>
Output:

column-reverse wrap-reverse: It arrange the row same as row-reverse top to bottom and wrap-reverse property This property is used to reverse the flow of the flex items when they wrap to new lines. Syntax:

flex-flow:column-reverse wrap-reverse; 
Example: html
<!DOCTYPE html>

<head>
    <title>flex-flow property</title>
    <style>
        #main {
            width: 400px;
            height: 300px;
            border: 2px solid black;
            display: flex;
            flex-flow: column-reverse wrap-reverse;
        }
        
        #main div {
            width: 100px;
            height: 50px;
        }
        
        h1 {
            color: #009900;
            font-size: 42px;
            margin-left: 50px;
        }
        
        h3 {
            margin-top: -20px;
            margin-left: 50px;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>The flex-flow:column-reverse wrap-reverse</h3>
    <div id="main">
        <div style="background-color:#009900;">1</div>
        <div style="background-color:#00cc99;">2</div>
        <div style="background-color:#0066ff;">3</div>
        <div style="background-color:#66ffff;">4</div>
        <div style="background-color:#660066;">5</div>
        <div style="background-color:#663300;">6</div>
    </div>
</body>

</html>
Output:

Supported Browser :

  • Google Chrome 29.0
  • Internet Explorer 11.0
  • Mozila Firefox 28.0
  • Safari 9.0
  • Opera 17.0

CSS flex-flow Property – FAQs

What is the flex-flow property in CSS?

The flex-flow property in CSS is a shorthand property for setting both the flex-direction and flex-wrap properties in one line. It controls both the direction and wrapping behavior of flex items.

How do I use flex-flow to set a row direction with wrapping?

You can set a row direction with wrapping using: flex-flow: row wrap; . This arranges items in a row and allows them to wrap onto a new line if necessary.

What values can flex-flow accept?

Flex-flow accepts a combination of any flex-direction value (row, row-reverse, column, column-reverse) and any flex-wrap value (nowrap, wrap, wrap-reverse). For example: flex-flow: column wrap; .

What is the default value of flex-flow?

The default value of flex-flow is row nowrap, meaning items are arranged in a row and do not wrap.

Can I set only one value with flex-flow?

Yes, if you only set one value, the other property will take its default value. For example, flex-flow: column; sets flex-direction to “column” while keeping flex-wrap at “nowrap.”



Next Article

Similar Reads

three90RightbarBannerImg
  翻译: