GitHub 博客园 Nanakon

【居中】垂直居中

垂直居中的几种实现方法

 

 

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <style>
        .wrap {
            width: 300px;
            height: 300px;
            border: 3px solid #ddd;
            display: table;
            *position: relative;
        }
        .hack {
            display: table-cell;
            vertical-align: middle;
            *position: absolute;
            *top: 50%;
        }
        .cnt {
            *position: relative;
            *top: -50%;
        }
    </style>
    <div class="wrap">
        <div class="hack">
            <div class="cnt">content</div>
        </div>
    </div>
    <div class="wrap">
        <div class="hack">
            <div class="cnt">
                <img src="http://pic002.cnblogs.com/images/2012/382256/2012080118323766.gif" width="50%">
            </div>
        </div>
    </div>
</body>
</html>

 

 

纯CSS实现未知尺寸图片垂直居中

posted on 2013-03-14 11:02  jzm17173  阅读(147)  评论(0编辑  收藏  举报

导航

轻音