参考文章
https://www.html.cn/archives/6308
动态垂直居中对齐
点击查看【codepen】
对于动态高度的元素,可以实现真正的垂直居中对齐
其他方式实现
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>* {margin: 0;padding: 0;}html,body {height: 100%;}body {width: 100%;height: 100%;}/* 关键样式 */.element {text-align: center;position: relative;top: 50%;transform: translateY(-50%);}</style></head><body><div class="element"><p>你好</p><p>你好</p></div></body></html>
