CSS Grid: Create Your First CSS Grid
CSS Grid helps you easily build complex web designs. It works by turning an HTML element into a grid container with rows and columns for you to place children elements where you want within the grid.
Turn any HTML element into a grid container by setting its
display property to grid. This gives you the ability to use all the other properties associated with CSS Grid.
Note
In CSS Grid, the parent element is referred to as the container and its children are called items.
In CSS Grid, the parent element is referred to as the container and its children are called items.
<style> .d1{background:LightSkyBlue;} .d2{background:LightSalmon;} .d3{background:PaleTurquoise;} .d4{background:LightPink;} .d5{background:PaleGreen;} .container { font-size: 40px; width: 100%; background: LightGray; display:grid; } </style> <div class="container"> <div class="d1">1</div> <div class="d2">2</div> <div class="d3">3</div> <div class="d4">4</div> <div class="d5">5</div> </div>
1
2
3
4
5
Simply creating a grid element doesn't get you very far. You need to define the structure of the grid as well. To add some columns to the grid, use the grid-template-columns property on a grid container as demonstrated below:
.container { display: grid; grid-template-columns: 50px 50px; }
This will give your grid two columns that are 50px wide each.
The number of parameters given to the
grid-template-columns property indicates the number of columns in the grid, and the value of each parameter indicates the width of each column.
1
2
3
4
5
grid-template-rows in the same way we used grid-template-columns.
let us add two rows to the grid that are
50px tall each. and three grid columns with 100px wide1
2
3
4
5
Comments
Post a Comment