html中div居中


鉴于每次都有人问css垂直居中,现在写个小例子。。。

<html>

<head>
    <title>测试</title>
    <style>
        div {
            position: absolute;
            top: 50%;
            left: 50%;
            margin: -150px 0 0 -200px;
            width: 400px;
            height: 300px;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

效果是:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM