Stacking Divs from Bottom to Top

前端 未结 7 2185
北荒
北荒 2020-12-04 09:46

When appending divs to a div with a fixed height, the child divs will appear from top to bottom, sticking at the top border.

┌─────         


        
7条回答
  •  不思量自难忘°
    2020-12-04 10:19

    We can simply use CSS transform to archive this.

    I created a codepen for it. https://codepen.io/king-dev/pen/PoPgXEg

    .root {
      transform: scaleY(-1);
    }
    .root > div {
      transform: scaleY(-1);
    }
    

    The idea is to flip the root first horizontally and then flip direct children divs again.

    NOTE: the above method also reverses the order of divs. If you simply want to place them to start from bottom you can do the following.

    .root {
      display: flex;
      flex-direction: column;
      height: 100px;
      overflow-y: auto;
    }
    .root > div:first-child {
      margin-top: auto;
    }
    

提交回复
热议问题