css垂直居中两种最简单方法

一、使用transform: translateY

 1 .modal .content{
 2     position: absolute;
 3     top: 50%;
 4     transform: translateY(-50%);
 5     left: 55rpx;
 6     right: 55rpx;
 7     width: 640rpx;
 8     height: 272rpx;
 9     background-color: #fff;
10     z-index: 1111;
11     border-radius: 16rpx;
12 }

二、使用margin:auto

 1 .modal .content{
 2     position: absolute;
 3     width: 200rpx;
 4     height: 200rpx;
 5     top: 0;
 6     bottom: 0;
 7     left: 0;
 8     right: 0;
 9     margin: auto;
10 }

  

原文地址:https://www.cnblogs.com/chengzi/p/13594903.html