CSS Grid: Align an Item Vertically using align-self

There's a way to align an item vertically . To do this, you use the align-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 cell
start: 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.stretch
1
2
3
4
5
2.start
1
2
3
4
5
3.center
1
2
3
4
5
4.end
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>
source

Comments

Popular posts from this blog

ES6 : 5 Prevent Object Mutation

ES6: 1 Explore Differences Between the var and let Keywords

CSS Grid: Reduce Repetition Using the repeat Function