DEV Community

Cover image for How to add tailwind CSS grid to your project.
Sampson Ovuoba for Devwares

Posted on • Originally published at devwares.com on

How to add tailwind CSS grid to your project.

Tailwind CSS boasts of many classes that we can use to style our projects. In today’s Tailwind CSS tutorial, we will look closely at adding Tailwind CSS grid to our projects.

The Tailwind CSS grid template columns are the alternative to CSS grid-template columns. This property is used to set the number of columns and the size of the grid columns.

Today, in our Tailwind CSS tutorial, we will look at the various grid columns classes available and build an example.

Grid Template columns

grid-cols-1: the row concedes one column
grid-cols-2: the row concedes two columns
grid-cols-3: the row concedes three columns
grid-cols-4: the row concedes four columns
grid-cols-5: the row concedes five columns
grid-cols-6: the row concedes six columns
grid-cols-7: the row concedes seven columns
grid-cols-8: the row concedes eight columns
grid-cols-9: the row concedes nine columns
grid-cols-10: the row concedes ten columns
grid-cols-11: the row concedes eleven columns
grid-cols-12: the row concedes twelve columns
grid-cols-none: this do not follow the grid-column property

Syntax

The necessary syntax to use when using this class in your project will look like the code below

Code:

<element class = “gird gird-cols-number>Content of the element </element>
Enter fullscreen mode Exit fullscreen mode

Building a grid column

We are going to try an example and build a grid column.

Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>grid column</title>
    <link rel="stylesheet" href="style.css">
</head>

<body class="text-center ">
    <div class="flex justify-center">
        <img src="images/devwares-logo.png" alt="" class="w-24">
    </div>

    <h2 class="text-blue-700 text-4xl font-bold">Tailwind CSS grid-cols class</h2>
    <div class="grid grid-cols-4 gap-1 justify-evenly">
        <div class="bg-purple-700 w-26 h-12">1</div>
        <div class="bg-purple-500 w-26 h-12">1</div>
        <div class="bg-purple-300 w-26 h-12">1</div>
        <div class="bg-purple-500 w-26 h-12">1</div>
        <div class="bg-purple-400 w-26 h-12">1</div>
        <div class="bg-purple-300 w-26 h-12">6</div>
        <div class="bg-purple-200 w-26 h-12">7</div>
        <div class="bg-purple-100 w-26 h-12">8</div>
    </div>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

In the code above, we linked our Tailwind CSS file to our project after installation.
We went ahead to create the body of our project by adding some Tailwind CSS classes such as

  • Flex: sets our element in a flex
  • Justify-center: this centers our elements
  • Text-center: this centers our text content
  • Grid: this creates the grid columns
  • Grid-cols-4: this creates a 4 grid column
  • Justify-evenly: this distributes our element in evenly form

The project we created should look like the image below.

Tailwind CSS grid

Conclusion

In this tailwind CSS tutorial, we looked at what grid is and what is used for. We also further built a grid-column project to show how Tailwind CSS grid can be used in your project. I hope you found this content helpful and enjoyed it.

Design and code tailwind css websites 3x faster

We created a tool to visually build tailwind css components, prototypes, websites, and webapps. Ship projects faster using an intuitive tailwind builder and editor.Try Windframe out for free.

WINDFRAME

Resources

Top comments (0)