Tailwind Flex Shrink

This article will mainly center around Tailwind Flex shrink property, along with examples.

The shrink class in Tailwind CSS allows you to control how much an element should shrink inside a Flexbox layout.

By setting the flex-shrink CSS property, you can specify how much an element should shrink relative to its siblings when there’s not enough space in the container.

Tailwind Flex Shrink

The value of the flex-shrink property is a number that represents the element’s shrink factor.



Tailwind Flex Shrink Classes

ClassesOverview
shrink-0Using this class, you can set the flex-shrink property of a flex item to 0.
shrinkThis class allows you to set the flex-shrink property of a flex item to 1.

Tailwind flex-shrink-0

The shrink-0 class in Tailwind CSS is used to prevent an element from shrinking and taking less space available inside a Flexbox layout.

Syntax

<element class="flex-shrink-0"> Contents....</element>

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

Tailwind flex-shrink

This sets the shrink value to 1, which means that the flex items will shrink proportionally when there is not enough space in the container.

Syntax

<element class="flex-shrink">....</element>

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