CSS Grid: Align All Items Vertically using align-items
Sometimes you want all the items in your CSS Grid to share the same
alignment.
You can use the previously article on vertically align elements using align-self and align them individually, or you can align them all at once vertically by using
This property can accept all the same values align-self accepts, the difference being that it will move all the items in our grid to the desired alignment.
1.stretch
You can use the previously article on vertically align elements using align-self and align them individually, or you can align them all at once vertically by using
align-items
on your grid container.This property can accept all the same values align-self accepts, the difference being that it will move all the items in our grid to the desired alignment.
stretch: default value that all divs will fill to the cells, start: aligns the content at the top of all cell,center: aligns the content in the center of all cell,end: aligns the content at the bottom of all cell.
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
<style> .item1{background:LightSkyBlue;} .item2{background:LightSalmon;} .item3{background:PaleTurquoise;} .item4{background:LightPink;} .item5{background:PaleGreen;} .container { font-size: 40px; min-height: 300px; width: 100%; background: LightGray; display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; grid-gap: 10px; align-items: ; } </style> <div class="container"> <div class="item1">1</div> <div class="item2">2</div> <div class="item3">3</div> <div class="item4">4</div> <div class="item5">5</div> </div>
source
Comments
Post a Comment