CSS Grid: Align an Item Vertically using align-self
There's a way to align an item vertically . To do this, you use the
This property accepts the following values:
all changes will be on div number 3
1.stretch
2.start
3.center
4.end
html code
sourcealign-self property on an item. inside the grid container This property accepts the following values:
stretch the default value for align-self content fill the cellstart: aligns the content at the top of the cell,center: aligns the content in the center of the cell,end: aligns the content at the bottom of the cell.all changes will be on div number 3
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
html code
<style> .item1{background:LightSkyBlue;} .item2{background:LightSalmon;} .item3 { background: PaleTurquoise; align-self :;
} .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; } </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>
Comments
Post a Comment