DIV的子Div居中对齐的一种方法

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        html,body{
            padding: 0;
            margin: 0;
            width: 100%;
            height: 100%;
        }

        .bg{
            position: relative;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #000;
            font-size:0px;
            letter-spacing:0px;
        }

        .login{
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -240px;
            margin-left: -440px;
            width:880px;
            height: 480px;
            background-repeat: no-repeat;
            background-position: center;
            background-color: #FFF;
            *display: inline;
            zoom:1;
        }
    </style>
</head>
<body>
    <div>
        <div></div>
    </div>
</body>
</html>

上外边据跟左外边据都设为负的宽高的一半,

50%的话距上边是50%大盒子的宽高,正好多了小盒子的一半,

所以用负的外边据给提上去

你可能感兴趣的:(DIV的子Div居中对齐的一种方法)