盒子垂直水平居中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            /*此方法必须固定宽高*/
            width: 200px;
            height: 200px;
            background-color: red;
            margin: auto;
            position: absolute;
            top: 0; left: 0; bottom: 0; right: 0;
        }

    </style>
</head>
<body>
<div class="box">
    5424
</div>
</body>
</html>

方法1   ie8可用

 .box{
            /*此方法必须固定宽高*/
            width: 200px;
            height: 200px;
            background-color: red;
            margin: auto;
            position: absolute;
            top: 0; left: 0; bottom: 0; right: 0;
        }

方法2

原文地址:https://www.cnblogs.com/aqigogogo/p/7592879.html