Tailwind grid responsive 4 column blocks

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

When it comes to tailwind layouts we have basically two main options.
If you know me, I use Flex for a lot of things. It's one of these things you start with and end up using for a lot of elements.
Today however I want to explore some grid action in Tailwind and see just how easy it can be.
We'll be creating a 4 column block layout for large devices, on tablet size they should stack 2-2 and on mobile, it should be 1 column.
The end result is as the following:

Let's start with our basic structure and style from there.
<div>
<div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
As you can see, I choose a double wrapper, the top div will be our container and the inner one will be the actual grid.
Let's add some basic styles for the containers first.
<div class="container mx-auto">
<div class="grid grid-cols-4 gap-6">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
This will already give us quite a good column space.

Let's quickly add some styling for our blocks.
<div class="container mx-auto">
<div class="grid grid-cols-4 gap-6">
<div
class="flex justify-center text-6xl border-2 border-gray-300 rounded-xl p-6 bg-gray-100"
>
1
</div>
<div
class="flex justify-center text-6xl border-2 border-gray-300 rounded-xl p-6 bg-gray-100"
>
2
</div>
<div
class="flex justify-center text-6xl border-2 border-gray-300 rounded-xl p-6 bg-gray-100"
>
3
</div>
<div
class="flex justify-center text-6xl border-2 border-gray-300 rounded-xl p-6 bg-gray-100"
>
4
</div>
</div>
</div>

Pretty solid right?
However, this is not yet responsive, luckily for us, the Tailwind grid is super easy to make responsive.
All we have to do is add the breakpoints on our grid element.
Remember: Tailwind is mobile-first so that will be the mobile view.
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"></div>
You can find the full demo on this Codepen.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter