How to center div vertically inside of absolutely positioned parent div

前端 未结 9 1885
闹比i
闹比i 2020-12-02 04:48

I am trying to get blue container in the middle of pink one, however seems vertical-align: middle; doesn\'t do the job in that case.

9条回答
  •  不思量自难忘°
    2020-12-02 05:14

    Center vertically and horizontally:

    .parent{
      height: 100%;
      position: absolute;
      width: 100%;
      top: 0;
      left: 0;
    }
    .c{
      position: absolute;
      top: 50%;
      left: 0;
      right: 0;
      transform: translateY(-50%);
    }
    

提交回复
热议问题