Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Grid Utilities | Layout Basics
Tailwind CSS: Styling for Modern Web Development
course content

Contenido del Curso

Tailwind CSS: Styling for Modern Web Development

Tailwind CSS: Styling for Modern Web Development

1. Introduction and Setup
2. Core Concepts and Basic Styling
3. Building Basic Components
4. Layout Basics
5. Responsiveness and Customization

bookGrid Utilities

Another way of organizing website content is through grids. Tailwind CSS offers powerful utilities for creating grid layouts. This chapter will explain how to use Tailwind CSS grid utilities to establish grid containers and items.

Grid Container

To define a grid container, use the grid class. You can control the number of columns, the gaps between rows and columns, and more.

html

index

css

index

js

index

copy

Explanation

  1. grid: Sets the display of the element to grid;
  2. grid-cols-3: Defines a grid with three columns;
  3. gap-4: Adds a gap of 1rem (16px) between grid items.

Grid with Rows

html

index

css

index

js

index

copy

grid-rows-2: Defines a grid with two rows.

Controlling Column and Row Sizes

You can control the sizes of columns and rows using grid-cols-{n} and grid-rows-{n} classes, where {n} represents the number of columns or rows. You can also use fractional units (fr), percentages, and other sizing units.

html

index

css

index

js

index

copy

Explanation

  1. col-span-2: Spans the element across two columns;
  2. col-span-3: Spans the element across all three columns.

Fixed and Flexible Sizes

html

index

css

index

js

index

copy

Explanation

  1. w-1/2: Sets the width of the element to 50% of its container;
  2. w-full: Sets the width of the element to 100% of its container;
  3. w-1/3: Sets the width of the element to 33.33% of its container.

Grid Template Columns and Rows

You can use specific utility classes to define the number and width of columns and rows in your grid layout.

Custom Grid Columns

html

index

css

index

js

index

copy

Explanation

  1. grid-cols-4: Defines a grid with four columns;
  2. col-span-1: Spans the element across one column;
  3. col-span-2: Spans the element across two columns.

Custom Grid Rows

html

index

css

index

js

index

copy

Explanation

  1. grid-rows-3: Defines a grid with three rows;
  2. row-span-2: Spans the element across two rows;
  3. row-span-1: Spans the element across one row.

Note

Please refer to the official documentation for more information about the Tailwind CSS Grid.

1. Which class sets the display property to grid?
2. How do you define a grid with three columns?
Which class sets the display property to grid?

Which class sets the display property to grid?

Selecciona la respuesta correcta

How do you define a grid with three columns?

How do you define a grid with three columns?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 5
some-alt