Tailwind Flex Grow

In this article, we’ll delve deeper into the Tailwind Flex Grow with examples to expand our understanding of its usage.

Tailwind grow property is a useful utility that enables the customization of the growth behavior of an element inside a Flexbox layout.

This class sets the flex-grow CSS property, which is responsible for determining how much an element should grow compared to its siblings when there is extra space in the container.

The value of the flex-grow property is a number that represents the growth factor of the element, with higher values indicating a higher priority for growth.

If we apply the grow class to an element, it will grow to fill any extra space available.

Syntax

<element class="grow"> </element>

This example focuses on the usage of the grow 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-3 text-slate-800">grow class in Tailwind CSS</p> <div id="main" class="flex justify-evenly space-x-2 ml-12 mr-12 text-rose-50 font-medium"> <div class="rounded bg-gray-600 h-10 px-2"> Normal div</div> <div class="rounded bg-gray-500 grow h-10 px-2"> flex-grow </div> <div class="rounded bg-gray-600 h-10 mr-12 px-2"> Normal div</div> </div> </body> </html>


Tailwind Flex Grow Values

To use the Flex Grow class in Tailwind CSS, simply add the “flex-grow” class to a flex item.

You can then set the value of the class using one of the following numeric values:

ValuesOverview
flex-grow-0The item will not grow at all
flex-grow-1The item will grow to fill any available space
flex-grow-2The item will grow twice as much as an item with a value of 1, and so on

Tailwind Flex-grow-0

The grow-0 class in Tailwind CSS is applied to an element to prevent it from growing and taking up additional space within a Flexbox layout.

Syntax

<element class="grow-0"> </element>

This example highlights the use case of the grow-0 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-3 text-slate-800">grow-0 class in Tailwind CSS</p> <div id="main" class="flex justify-evenly space-x-2 ml-12 mr-12 text-rose-50 font-medium"> <div class="rounded bg-gray-600 grow h-10"> flex-grow</div> <div class="rounded bg-gray-500 grow-0 h-10 px-2"> flex-grow-0 </div> <div class="rounded bg-gray-600 grow h-10 mr-12"> flex-grow</div> </div> </body> </html>

Here’s an example of how to use all three classes together to create a flexible three-column 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-3 text-slate-800">grow-1 class in Tailwind CSS</p> <div id="main" class="flex justify-evenly space-x-2 ml-12 mr-12 text-rose-50 font-medium"> <div class="rounded bg-gray-600 flex-grow-0 h-10"> flex-grow</div> <div class="rounded bg-gray-500 flex-grow-1 h-10 px-2"> flex-grow-1 </div> <div class="rounded bg-gray-600 flex-grow-2 h-10 mr-12"> flex-grow-2</div> </div> </body> </html>
We value your feedback.
+1
0
+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 *