Learn to create a responsive web design using Grid Layout in css3

Introduction of Grid Layout in css3.0

Grid layout using css3
Grid layout using css3

With the help of CSS GridLayout we do any critical web design to design the layout of the web page with the help of rows and columns. It is a two dimensional technique that we use to make the web page responsive and mobile friendly. There are CSS grid layouts, we can design web page very easily without float and positioning.

Browser Support:

css grid layout support
css grid layout support


Display Property:

The layout is used by the display property in a container In this property we grid the value of the display.

Example:
.grid-container {
  display: grid;
}

Grid Columns & Rows:

Grid column
Grid column

In a grid layout we call the vertical line the Grid Column and in the grid layout we call the horizontal line the Grid Row.
Grid row
Grid row

Grid Gaps:

The spaces between each column/row are called gaps.
Grid Gaps

Grid Gaps


CSS Grid Layout We use this property of grid to create a gap between any two columns or rows, we can use this property in 3 ways.

The first property is grid-column-gap, with the help of this property, we define the gap between all the columns present in the grid.

Example:
.grid-container {
  display: grid;
  grid-column-gap: 50px;
}

The second property is grid-row-gap. With the help of this property, we define the gap between all the rows present in the grid.

Example:
.grid-container {
  display: grid;
  grid-row-gap: 50px;
}

And the third property is grid-gap. With the help of this property, we do this to give a gap between grid and column together. If we want to keep the gap between both rows and columns, then we use this property. Our code also reduces with the use of We can use this property of grid-gap in two ways.
 If we give two values ​​to the property of grid, then here the first value defines the column and the second value defines the row, in this way we define the value of both the row and the column. The gap between the two has to be defined separately.

Example:
.grid-container {
  display: grid;
  grid-gap: 50px 100px;
}

When we have to keep the gap between the disease and the column the same, then here we will give the same value of the great gap.

Example:
.grid-container {
   display: grid;
   grid-gap: 50px;
}

The grid-template-columns Property:

The next property in the CSS grid layout is grid-template-columns If we have to define 4 columns in a grid layout then we will use this property if we have to create four columns then we will give the value of grid-template-columns four times and if If you want to make it twice, you will give the value of grid-template-columns twice.

Example:
.grid-container {
   display: grid;
   grid-template-columns: auto auto auto auto;
}

The grid-template-rows Property:

The next property in the CSS grid layout is grid-template-rows
Just as we use grid-template-columns, similarly we use grid-template-rows. If we have to define 4 rows in a grid layout, then we will use this property if we want to create four rows. You will give the value of grid-template-rows four times and if you want to create it twice, you will give the value of grid-template-rows twice.

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

The justify-content Property:

gird-justify-property
gird-justify-property

Next property of css grid layout app justify-content property we use this property to justify online all the cells inside the grid-container when we use this property then all the salesmen present in the great layout of the container Returns online with or affects all cells within container width


In CSS Grid Layout we can give the value of justify-content as follows:

.grid-container {
  display: grid;
  justify-content: space-evenly;
}
or
.grid-container {
  display: grid;
  justify-content: space-around;
}
or
.grid-container {
  display: grid;
  justify-content: space-between;
}
or
.grid-container {
  display: grid;
  justify-content: center;
}
or
.grid-container {
  display: grid;
  justify-content: start;
}
or
.grid-container {
  display: grid;
  justify-content: end;
}

The align-content Property:

align-content property
align-content property

The way we use the justify-content property in grid layout, we use the align-content property in the same way, we use this property when we have to make all the sales in the container online by recording the height of the container.

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

CSS Grid Item:

Grid Item
Grid Item

Child Elements (Items):

All the cells present in the grid-container . The CSS grid-container has a By default one cell. Here cell means the grid and column to be constituted where grid-column together form a cell. Multiple grid items in CSS. We use the grid-column property to create .

The grid-column Property:

Grid-column property
Grid column

We use the Grid-column property in exactly the same way as we use the col-span in the table tag in HTML. In the Grid Column property we have to give the value of grid-column Start and grid-column end Property.

Example:
.item1 {
  grid-column: 1/5;
}

Here the value of the grid-column where we used 1 defines the column's start point and 5 defines the end of the column.

The grid-row Property:
grid-row property
grid-row property

We use the grid-row property the same way we use row-span in the table tag in HTML. In grid-row property we have to give the value of grid-row start and  grid-row end property.

Example:
.item1 {
   grid-row: 1/4;
}

The grid-area property:
grid-area property
grid-area property 

The grid-area property can be used as a shorthand property for the grid-row-start, grid-column-start, grid-row-end and the grid-column-end properties.

Example:

Make "item8" start on row-line 1 and column-line 2, and end on row-line 5 and column line 6:

.item8 {
   grid-area: 1/2/5/6;
}

Naming Grid Items:

The grid-area property can also be used to assign names to grid items.
Named grid items
Named grid items

Named grid items can be referred to by the grid-template-areas property of the grid container.

Example:
Item1 gets the name "myArea" and spans all five columns in a five columns grid layout:

.item1 {
  grid-area: myArea;
}
.grid-container {
  grid-template-areas: 'myArea myArea myArea myArea myArea';
}

Each row is defined by apostrophes (' ')

The columns in each row is defined inside the apostrophes, separated by a space.

Example:
Let "myArea" span two columns in a five columns grid layout (period signs represent items with no name):

.item1 {
  grid-area: myArea;
}
.grid-container {
  grid-template-areas: 'myArea myArea . . .';
}

Example:
Name all items, and make a ready-to-use webpage template:

.item1 { grid-area: header; }
.item2 { grid-area: menu; }
.item3 { grid-area: main; }
.item4 { grid-area: right; }
.item5 { grid-area: footer; }

.grid-container {
  grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';
}

The Order of the Items:
order of item
order of item

The Grid Layout allows us to position the items anywhere we like.
The first item in the HTML code does not have to appear as the first item in the grid.

Example:
.item1 { grid-area: 1 / 3 / 2 / 4; }
.item2 { grid-area: 2 / 3 / 3 / 4; }
.item3 { grid-area: 1 / 1 / 2 / 2; }
.item4 { grid-area: 1 / 2 / 2 / 3; }
.item5 { grid-area: 2 / 1 / 3 / 2; }
.item6 { grid-area: 2 / 2 / 3 / 3; }

You can re-arrange the order for certain screen sizes, by using media queries:

Example
@media only screen and (max-width: 500px) {
  .item1 { grid-area: 1 / span 3 / 2 / 4; }
  .item2 { grid-area: 3 / 3 / 4 / 4; }
  .item3 { grid-area: 2 / 1 / 3 / 2; }
  .item4 { grid-area: 2 / 2 / span 2 / 3; }
  .item5 { grid-area: 3 / 1 / 4 / 2; }
  .item6 { grid-area: 2 / 3 / 3 / 4; }
}







Post a Comment

0 Comments