Free Ebook cover Complete CSS course

Complete CSS course

4.5

(2)

35 pages

Grid in CSS

Capítulo 29

Estimated reading time: 3 minutes

Audio Icon

Listen in audio

0:00 / 0:00

Grid in CSS

The Grid in CSS is a powerful tool that allows the creation of complex and responsive layouts for websites and web applications. With it, it is possible to divide the page into rows and columns, creating a structure that facilitates the positioning of elements.

How the Grid works in CSS

The Grid in CSS works by creating a container that defines the grid of the page. This container is divided into rows and columns, which can be defined manually or through a CSS automatic function.

To define the Grid in CSS, it is necessary to use the properties display: grid and grid-template-columns and grid-template-rows. The first property defines the layout type, while the other two define the number and size of columns and rows.

In addition, you can set the spacing between columns and rows with the grid-column-gap and grid-row-gap properties.

Benefits of Grid in CSS

CSS Grid offers several benefits for developing responsive layouts. Some of the main advantages are:

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

  • Greater control over placement of elements on the page;
  • Increased flexibility to create complex layouts;
  • Easier to adapt the layout to different screen sizes;
  • Easier layouts with elements in different sizes and proportions.

Example usage of Grid in CSS

To exemplify the use of the Grid in CSS, let's create a simple layout with three columns and two rows:

```html
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
``` ```css .container { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); grid-column-gap: 10px; grid-row-gap: 10px; } .item { background-color: #ccc; padding: 20px; text-align: center; } ```

In this example, we create a container with the .container class and six elements with the .item class. We define the layout as a grid with three columns and two rows, with a spacing of 10 pixels between columns and rows.

With Grid in CSS, you can create complex and responsive layouts with ease, giving you greater control and flexibility for developing websites and web applications.

Now answer the exercise about the content:

_What is one of the advantages of Grid in CSS for the development of responsive layouts?

You are right! Congratulations, now go to the next page

You missed! Try again.

The CSS Grid system provides an advantage in creating responsive layouts by making it easier to adapt to different screen sizes. This is achieved through its ability to define and adjust rows and columns flexibly, as highlighted in the text.

Next chapter

Media Queries in CSS

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.