Tailwind Flex Direction

In this article, we’ll take a closer look at Tailwind flex direction property and how it works in Tailwind CSS.

With the flex-direction property, we can control the direction in which the flex items are displayed.

Tailwind Flex Directions

The flex-direction property is used to set the direction of the flex container’s main axis.

The main axis is the axis along which the flex items are laid out.

Syntax

<element class="flex flex-'direction'"> Contents....</element>
Note: The flex-direction class can only be used if the flex class is already being used.


Tailwind Flex Direction Classes

Tailwind CSS supports a range of flex direction values that can be applied to flex containers to control the layout of their child elements.

Below is a list of some of the most commonly used flex direction class values in Tailwind CSS:

ClassesOverview
flex-rowThis value is used to set the direction of the flex container to be horizontal, with items arranged in a row from left to right.
flex-row-reverseThis value is used to set the direction of the flex container to be horizontal, with items arranged in a row from right to left.
flex-colThis value is used to set the direction of the flex container to be vertical, with items arranged in a column from top to bottom.
flex-col-reverseThis value is used to set the direction of the flex container to be vertical, with items arranged in a column from bottom to top.

Now that we have explored the different types of flex direction class values supported by Tailwind CSS, let’s take a look at some examples of how they can be used practically.


Tailwind Flex Direction Row

The flex-row class in Tailwind CSS is used to create a Flexbox layout that is oriented in a row.

This means that the elements inside the container will be arranged in a row, starting from the left and going towards the right.

Syntax

<element class="flex flex-row"> </element>

In this example, we’ll explore how to use the flex-row class in Tailwind CSS to create a row-oriented Flexbox layout:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium my-2 text-slate-800">flex-row class in Tailwind CSS</p> <div id="main" class="flex flex-row justify-evenly items-center text-rose-50 font-semibold"> <div class="bg-fuchsia-900 rounded-sm w-24 h-12">1st</div> <div class="bg-fuchsia-800 rounded-sm w-24 h-12">2nd</div> <div class="bg-fuchsia-700 rounded-sm w-24 h-12">3rd</div> <div class="bg-fuchsia-600 rounded-sm w-24 h-12">4th</div> <div class="bg-fuchsia-500 rounded-sm w-24 h-12">5th</div> </div> </body> </html>

Tailwind Flex Direction Reverse

The flex-row-reverse class in Tailwind CSS is a useful class for creating a Flexbox layout with elements arranged in a row from right to left.

This effectively reverses the order in which the items are laid out.

In other words, the last item becomes the first item, and the first item becomes the last item.

Syntax

<element class="flex flex-row-reverse"> </element>

In this code snippet, we showcase how the flex-row-reverse class is utilized in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium my-2 text-slate-800">flex-row-reverse class in Tailwind CSS</p> <div id="main" class="flex flex-row-reverse justify-evenly items-center text-rose-50 font-semibold"> <div class="bg-fuchsia-900 rounded-sm w-24 h-12">1st</div> <div class="bg-fuchsia-800 rounded-sm w-24 h-12">2nd</div> <div class="bg-fuchsia-700 rounded-sm w-24 h-12">3rd</div> <div class="bg-fuchsia-600 rounded-sm w-24 h-12">4th</div> <div class="bg-fuchsia-500 rounded-sm w-24 h-12">5th</div> </div> </body> </html>


Tailwind Flex Direction Col

The flex-col class in Tailwind CSS is a class used to create a column-oriented Flexbox layout.

This results in the elements inside the container being arranged in a column from top to bottom.

Syntax

<element class="flex flex-col"> </element>

This example provides an overview of the flex-col class in Tailwind CSS:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium my-2 text-slate-800">flex-col class in Tailwind CSS</p> <div id="main" class="flex flex-col justify-evenly items-center text-rose-50 font-semibold"> <div class="bg-fuchsia-900 rounded-sm w-24 h-12">1st</div> <div class="bg-fuchsia-800 rounded-sm w-24 h-12">2nd</div> <div class="bg-fuchsia-700 rounded-sm w-24 h-12">3rd</div> <div class="bg-fuchsia-600 rounded-sm w-24 h-12">4th</div> <div class="bg-fuchsia-500 rounded-sm w-24 h-12">5th</div> </div> </body> </html>

Tailwind Flex Col Reverse

Tailwind flex-col-reverse class is a useful class that allows you to create a column-oriented Flexbox layout with elements arranged in reverse order, from bottom to top.

This reverses the order in which the items are laid out in the column, with the last item becoming the first item, and the first item becoming the last item.

Syntax

<element class="flex flex-col-reverse"> </element>

For this example, we will examine the flex-col-reverse class in Tailwind:

Example: 

<!DOCTYPE html> <html><head> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="text-center"> <h1 class="text-gray-600 text-2xl font-semibold"> MrExamples </h1> <p class="font-medium my-2 text-slate-800">flex-col-reverse class in Tailwind CSS</p> <div id="main" class="flex flex-col-reverse justify-evenly items-center text-rose-50 font-semibold"> <div class="bg-fuchsia-900 rounded-sm w-24 h-12">1st</div> <div class="bg-fuchsia-800 rounded-sm w-24 h-12">2nd</div> <div class="bg-fuchsia-700 rounded-sm w-24 h-12">3rd</div> <div class="bg-fuchsia-600 rounded-sm w-24 h-12">4th</div> <div class="bg-fuchsia-500 rounded-sm w-24 h-12">5th</div> </div> </body> </html>

We value your feedback.
+1
1
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *