CSS效果——绝对居中

实现效果

不论窗口尺寸,都可以垂直和水平居中。

 

代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>居中效果</title>
    <link href="style.css" rel="stylesheet">
    <style type="text/css">
        .warp {
            width:0;
            height:0;
            position:fixed;
            left:50%;
            right:50%;
            top:50%;
            bottom:50%;
        }

        .loginPanel {
            width:500px;
            height:400px;
            margin-left:-250px;
            margin-top:-200px;
            background-color:#499ECA;
        }

    </style>
</head>
<body>
    <div class="warp">
        <div class="loginPanel">
            
        </div>
    </div>
</body>
</html>

 

posted @ 2017-11-28 19:17  大肥肥就是我  阅读(238)  评论(0编辑  收藏  举报