CSS代码使任何元素垂直居中

方法一:.element {  position: relative;  top: 50%;  transform: translateY(-50%);}   

方法二:

HTML:

<body> 
<div class="a1">
<div class="a2"></div>
</div>
</body>

css:
.a1{ 100%;height: 500px;display: table-cell;text-align: center;vertical-align: middle; }
.a2 { 50px; height:50px; background:green;display: table; }

原文地址:https://www.cnblogs.com/lily2015/p/4660872.html