Code Skiller logoCB Logo
Logo LearnLearnLogo PracticePracticeLogo HireHireLogo IDEIDE

CSS Grids

User image

Published by

sanya sanya

Published at: 28th Jul, 2023
1.62 mins read

CSS Grid is a powerful layout system that allows you to create complex, grid-based layouts on web pages. It provides a two-dimensional grid system, allowing you to define rows and columns, and place elements within those rows and columns.

CSS Grid is widely supported by modern browsers and offers a flexible and intuitive way to design responsive layouts.

The key Components of the CSS Grids are discussed further.

Grid Container

To create a grid layout, you need a container element, which becomes the grid parent or the grid container. You can set an element as a grid container by applying the display: grid; property to it.

.element { display: grid; }

Grid Tracks

Grid tracks are the rows and columns of the grid. You can define them explicitly using the grid-template-rows and grid-template-columns properties, or they can be created implicitly when items are placed on the grid.

.grid-container { display: grid; grid-template-rows: 100px 200px 300px; grid-template-columns: 1fr 2fr 1fr; }


Grid Items

Grid items are the elements that are placed within the grid container. They can be any HTML element, such as divs, images, or text. You can position grid items within the grid using the grid-row and grid-column properties.

.grid-item { grid-row: 1 / 3; grid-column: 2 / 4; }

Grid Lines

Grid lines are the horizontal and vertical lines that make up the grid. They separate the rows and columns. You can refer to grid lines when placing items using line-based positioning with properties like grid-row-start, grid-row-end, grid-column-start, and grid-column-end.

.element{ grid-row-start: inherit; grid-row-start: initial; grid-row-start: revert; grid-row-start: revert-layer; grid-row-start: unset;

}

Grid Areas

Grid areas are rectangular areas within the grid formed by the intersection of rows and columns. You can assign names to grid areas and use them to place items using the grid-area property.

.content { grid-area: content; background-color: #f1f1f1; }
.footer { grid-area: footer; background-color: #f1f1f1; }

Library

WEB DEVELOPMENT

Basic

HTML - Hyper Text Markup Language

CSS - Cascading Style Sheets

Cascading Style Sheets (CSS)

Selectors and Combinators

CSS Transforms

Units

CSS Icons and Colors

CSS Borders

CSS Margin

CSS Padding

CSS Dimensions

CSS Box Model

CSS Background

Pseudo Classes in CSS

CSS Positions

CSS Flexbox

Responsiveness in CSS

CSS Transitions

CSS Animations

Other CSS Properties

Var()

CSS Frameworks

CSS Grids

CSS Display Properties

JavaScript

Frontend

Backend

Interview Questions

FAANG QUESTIONS

On this page

Grid Container

Grid Tracks

Grid Items

Grid Lines

Grid Areas