Grid Auto Flow In Tailwind Css

This article aims to elaborate on Tailwind grid auto flow property with examples. The purpose of this class is to control the placement of grid items that are not explicitly placed by a grid-row or grid-column.

Tailwind Grid Auto Flow

It is important to know that when we use tailwind grid auto flow to set the placement of grid items, the grid container will calculate the amount of available space for the grid, as well as the size of each grid item, and will then place the items accordingly.



Tailwind Grid Auto Flow Classes

ClassesOverview
grid-flow-rowThis utility class allows you to set the placement of grid items to fill rows from left to right before moving on to the next row.
grid-flow-colGrid items are placed from top to bottom before moving on to the next column.
grid-flow-denseWhen this class is applied to a grid container, it enables the dense packing algorithm for grid items. This allows grid items to be placed into empty cells even if doing so creates holes in the grid.
grid-flow-row-denseGrid items are packed densely using the dense packing algorithm and are placed from left to right before moving on to the next row. In Tailwind, the grid-flow-row-dense utility class is a combination of the grid-flow-row and grid-flow-dense classes.
grid-flow-col-denseGrid items are packed densely and are placed from top to bottom before moving on to the next column. This utility class combines grid-flow-col and grid-flow-dense classes in Tailwind.

Tailwind Grid-flow-row

Tailwind grid-flow-row class is used to create a grid layout where items flow in rows.

By default, Tailwind uses the grid-flow-col class, which arranges items in columns.

The grid-flow-row class, on the other hand, arranges items in rows, which can be useful in certain situations, such as when you want to create a horizontal scrollable list.

Syntax

<element class="grid-flow-row"> Contents... </element>

This example focuses on the usage of the grid-flow-row 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">Grid Auto Flow in Tailwind</p> <p class="font-medium my-2 text-sm text-gray-500">Using grid-flow-row class</p> <div class="my-4 grid grid-rows-3 grid-cols-3 grid-flow-row gap-1 font-medium"> <div class="bg-gray-300 rounded-lg p-1 col-span-2">1st</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">2nd</div> <div class="bg-gray-300 rounded-lg p-1">3rd</div> </div> </body> </html>

Tailwind grid-flow-col

Tailwind grid-flow-col class is used to create a grid layout where items flow in columns.

The grid-flow-col class, on the other hand, arranges items in columns, which is the more common layout for grids.

Syntax

<element class="grid-flow-col"> Contents... </element>

For this example, let’s consider the grid-flow-col 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">Grid Auto Flow in Tailwind</p> <p class="font-medium my-2 text-sm text-gray-500">Using grid-flow-col class</p> <div class="my-4 grid grid-rows-3 grid-cols-3 grid-flow-col gap-1 font-medium"> <div class="bg-gray-300 rounded-lg p-1 col-span-2">1st</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">2nd</div> <div class="bg-gray-300 rounded-lg p-1">3rd</div> </div> </body> </html>

Tailwind Grid-flow-dense

The grid-flow-dense class is used to create a grid layout where items are arranged in a dense or compact manner.

In some cases, you may want to create a grid layout where items are arranged closer together to reduce whitespace and create a more compact design.

Syntax

<element class="grid-flow-dense"> Contents... </element>

In this example, we are going to make use of grid-flow-dense 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">Grid Auto Flow in Tailwind</p> <p class="font-medium my-2 text-sm text-gray-500">Using grid-flow-dense class</p> <div class="my-4 grid grid-rows-3 grid-cols-3 grid-flow-dense gap-1 font-medium"> <div class="bg-gray-300 rounded-lg p-1 col-span-2">1st</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">2nd</div> <div class="bg-gray-300 rounded-lg p-1">3rd</div> </div> </body> </html>

Tailwind Grid-flow-row-dense

The grid-flow-row-dense class is used to create a grid layout where items are arranged in a dense or compact manner, and flow in rows.

Syntax

<element class="grid-flow-row-dense"> Contents... </element>

This example portrays the application of grid-flow-row-dense 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">Grid Auto Flow in Tailwind</p> <p class="font-medium my-2 text-sm text-gray-500">Using grid-flow-row-dense class</p> <div class="my-4 grid grid-rows-3 grid-cols-3 grid-flow-row-dense gap-1 font-medium"> <div class="bg-gray-300 rounded-lg p-1 col-span-2">1st</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">2nd</div> <div class="bg-gray-300 rounded-lg p-1">3rd</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">4th</div> <div class="bg-gray-300 rounded-lg p-1">5th</div> </div> </body> </html>

Tailwind grid-flow-col-dense

Tailwind grid-flow-col-dense class is used to create a grid layout where items are arranged in a dense or compact manner, and flow in columns.

By default, Tailwind uses the grid-flow-col class, which arranges items in columns with equal spacing between them.

Syntax

<element class="grid-flow-col-dense"> Contents... </element>

The following example showcases the execution of the grid-flow-col-dense 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">Grid Auto Flow in Tailwind</p> <p class="font-medium my-2 text-sm text-gray-500">Using grid-flow-col-dense class</p> <div class="my-4 grid grid-rows-3 grid-cols-3 grid-flow-col-dense gap-1 font-medium"> <div class="bg-gray-300 rounded-lg p-1 col-span-2">1st</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">2nd</div> <div class="bg-gray-300 rounded-lg p-1">3rd</div> <div class="bg-gray-300 rounded-lg p-1 col-span-2">4th</div> <div class="bg-gray-300 rounded-lg p-1">5th</div> </div> </body> </html>
We value your feedback.
+1
0
+1
1
+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 *