Please Allow Notifications

If you want to get our blog posts notification, you can subscribe our website by clicking on allow notification button



FOLLOW US ON TWITTER



FOLLOW US



img/blogimg/css3.jpg


@coder 805

CSS3 GRID


2021-11-16 23:36 · 5 min read

CSS3 Grid system is useful for designing the responsive layout. Bootstrap framework is also using the Grid system for responsiveness. It's very easy to design a layout using a Grid system without using positioning and float property.

What is a CSS3 Grid system?

The CSS3 Grid system is used to create responsive layouts. The grid layout is based on a row and column system. A grid layout consists of a parent HTML element and with its child Elements.

  • Grid Container
    We use display property to create a grid container. We can use grid or inline grid values to create a grid container.
  • Grid items
    All children of Grid containers are Grid items. A grid container may contain rows and columns of grid items. The space between columns and rows is called a gap.
  • A grid container may contain rows and columns of grid items. The space between columns and rows is called a gap.
<style>
.tdb-grid-container{
display: grid;
grid-column-gap:20px;
grid-row-gap:20px;
/*grid gap is a shorthand property*/
grid-gap:<grid-row-gap> <grid-colum-gap>;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-grid-container{
display: grid;
grid-template-columns: auto auto auto;
background-color: black;
grid-gap:10px;
}
.tdb-grid-box {
margin:2px;
padding: 20px;
border: 1px solid white;
color:white;
font-size: 28px;
text-align: center;
}
</style>
</head>
<body>

<h1>CSS3 Grid System</h1>

<div class="tdb-grid-container">
<div class="tdb-grid-box">1</div>
<div class="tdb-grid-box">2</div>
<div class="tdb-grid-box">3</div>
<div class="tdb-grid-box">4</div>
</div>

</body>
</html>

 

What is a Grid Line?

The lines between rows and columns are called Gridlines. The lines between columns are called column lines and for rows, it is called row lines.

<style>
.grid-item1 {
grid-column-start: 1;
grid-column-end: 4;
grid-row-start: 1;
grid-row-end: 3;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-grid-container{
display: grid;
grid-template-columns: auto auto auto;
background-color: black;
grid-gap:10px;
}
.tdb-grid-box {
margin:2px;
padding: 20px;
border: 1px solid white;
color:white;
font-size: 28px;
text-align: center;
}
.tdb-item{
grid-column-start: 1;
grid-column-end: 3;
grid-row-start: 1;
grid-row-end: 4;
}
</style>
</head>
<body>

<h1>CSS3 Grid System</h1>

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

</body>
</html>

 

How to use grid-template-columns Property

The grid-template-columns property is used to specify the number of columns in a grid layout.

  • If we want to add 5 columns in a grid layout, we just need to specify the width of the items or we can also use "auto".

grid-template-columns: auto auto auto auto;
Here auto is used for the same width of items.
 

How to use grid-template-rows Property

The grid-template-row property is used to specify the number of rows in a grid layout.

  • If we want to add 2 rows in a grid layout, we just need to specify the height of the items or we can also use "auto" for the same height of the item blocks.
<style>
.grid-container{
display: grid;
grid-template-rows: 100px 150px;
}
</style>

Click on the try it button and try to run the code.

 

TAGS:






POST COMMENTS
No Comment

Please login to post comment




POPULAR POSTS

what is new in miui 11?...
best free web hosting services...
free website ssl security using cloudfla...
do you want to make money online?...
CSS3 @IMPORT RULES...
CSS3 RESPONSIVE UI...
Tables HTML...
How to host a web page in 10 minutes....
How to use CSS3 Overflow Property?...
CSS3 FUNCTIONS...
CSS3 FILTERS...
CSS3 SHAPES...


RECENT COMMENTS

2022-03-05 11:05
By coder on XAMPP - MySQL shutdown unexpectedly | How to fix MySQL crash unexpectedly
2021-10-12 12:34
By abnongoke on do you want to make money online?
2021-10-12 12:34
By abnongoke on how to get a free website domain name?
2021-10-12 12:34
By solar panel for shed on what is new in miui 11?
2021-10-12 12:34
By solar panel for shed on best free web hosting services
2021-10-12 12:34
By amos tanui on free website ssl security using cloudflare


SOCIAL SHARE



FOLLOW US ON TWITTER



FOLLOW US ON FACEBOOK



FOLLOW US







Recent Blogs



Contact Us

Subscribe Our News-Letter



Kashipur, 244713
Uttarakhand, India



© blog.theprodevelopers.com 2022. All Rights Reserved. Powered by Pro Developer