Our Recommendation for You Search your Query, You can find easily. for example search by book name or course name or any other which is related to your education

label name

PHP

CSS Grid

CSSCSS Grid Layout Module


Header

Menu

Main

Right

Footer


Grid Layout

The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.

Browser Support

The grid properties are supported in all modern browsers.





57.0 16.0 52.0 10 44

Grid Elements

A grid layout consists of a parent element, with one or more child elements.

Example

<div class="grid-container">
  <div class="grid-item">1</div>
  <div class="grid-item">2</div>
  <div class="grid-item">3</div>
  <div class="grid-item">4</div>
  <div class="grid-item">5</div>
  <div class="grid-item">6</div>
  <div class="grid-item">7</div>
  <div class="grid-item">8</div>
  <div class="grid-item">9</div>
</div>

1

2

3

4

5

6

7

8

9


Display Property

An HTML elemement becomes a grid container by setting the display property to grid or inline-grid.

Example

.grid-container {
  display: grid;
}

Example

.grid-container {
  display: inline-grid;
}
All direct children of the grid container automatically becomes grid items.

Grid Columns

The vertical line of grid items are called columns.


Grid Rows

The horizontal line of grid items are called rows.


Grid Gaps

The space between each column/row are called gaps.
You can adjust the gap size by using one of theses properties:
grip-column-gap
grip-row-gap
grip-gap

Example

The grid-column-gap property sets the gap between the columns:
.grid-container {
  display: grid;
  grid-column-gap: 50px;
}

Example

The grid-row-gap property sets the gap between the rows:
.grid-container {
  display: grid;
  grid-row-gap: 50px;
}

Example

The grid-gap property is a shorthand property for the grid-column-gap and the grid-row-gap properties:
.grid-container {
  display: grid;
  grid-gap: 50px 100px;
}

Example

The grid-gap property can also be used to set both the column gap and the row gap in one value:
.grid-container {
  display: grid;
  grid-gap: 50px;
}

Grid Lines

The line between columns are called column lines.
The line between rows are called row lines.
Refer to line numbers when placing a grid item in a grid container:

Example

Place a grid item at column line 1, and let it end on column line 3:
.item1 {
  grid-column-start: 1;
  grid-column-end: 3;
}

Example

Place a grid item at row line 1, and let it end on row line 3:
.item1 {
  grid-row-start: 1;
  grid-row-end: 3;
}


CSS Grid Container


1

2

3

4

5

6

7

8


Grid Container

To make an HTML element behave as a grid container, you have to set the display property to grid or inline-grid.
Grid containers consist of grid items, placed inside columns and rows.

The grid-template-columns Property

The grid-template-columns property defines the number of columns in your grid layout, and it can define the width of each column.
The value is a space-separated-list, where each value defines the the length of the respective column.
If you want your grid layout to contain 4 columns, specify the width of the 4 columns, or "auto" if all columns should have the same width.

Example

Make a grid with 4 columns:
.grid-container {
  display: grid;
  grid-template-columns: auto auto auto auto;
}
Note: If you have more than 4 items in a 4 columns grid, the grid will automatically add a new row to put the items in.
The grid-template-columns property can also be used to specify the size (width) of the columns.

Example

Set a size for the 4 columns:
.grid-container {
  display: grid;
  grid-template-columns: 80px 200px auto 40px;
}

The grid-template-rows Property

The grid-template-rows property defines the height of each row.

1

2

3

4

5

6

7

8

The value is a space-separated-list, where each value defines the the height of the respective row:

Example

.grid-container {
  display: grid;
  grid-template-rows: 80px 200px;
}

The justify-content Property

The justify-content property is used to align the whole grid inside the container.

1

2

3

4

5

6

Note: The grid's total width has to be less than the container's width for the justify-content property to have any effect.

Example

.grid-container {
  display: grid;
  justify-content: space-evenly;
}

Example

.grid-container {
  display: grid;
  justify-content: space-around;
}

Example

.grid-container {
  display: grid;
  justify-content: space-between;
}

Example

.grid-container {
  display: grid;
  justify-content: center;
}

Example

.grid-container {
  display: grid;
  justify-content: start;
}

Example

.grid-container {
  display: grid;
  justify-content: end;
}

The align-content Property

The align-content property is used to vertically align the whole grid inside the container.

1

2

3

4

5

6

Note: The grid's total height has to be less than the container's height for the align-content property to have any effect.

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: center;
}

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: space-evenly;
}

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: space-around;
}

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: space-between;
}

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: start;
}

Example

.grid-container {
  display: grid;
  height: 400px;
  align-content: end;
}