How can I position my div at the bottom of its container?

前端 未结 24 2790
广开言路
广开言路 2020-11-22 00:46

Given the following HTML:



        
24条回答
  •  野性不改
    2020-11-22 01:35

    CSS Grid

    Since the usage of CSS Grid is increasing, I would like to suggest align-self to the element that is inside a grid container.

    align-self can contain any of the values: end, self-end, flex-end for the following example.

    #parent {
      display: grid;
    }
    
    #child1 {
      align-self: end;
    }
    
    /* Extra Styling for Snippet */
    
    #parent {
      height: 150px;
      background: #5548B0;
      color: #fff;
      padding: 10px;
      font-family: sans-serif;
    }
    
    #child1 {
      height: 50px;
      width: 50px;
      background: #6A67CE;
      text-align: center;
      vertical-align: middle;
      line-height: 50px;
    }
    1

提交回复
热议问题