马丁传奇

导航

使当前对象相对于上层DIV 水平、垂直居中定位

<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>使当前对象相对于上层DIV 水平、垂直居中定位</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <style type="text/css">
        .thumbBox{
            width:400px;
            height:500px;
            border:1px solid red;           
        }
        .imgGoods{
            position:relative;
            left:50%;
            top:50%;
            margin-left:-135px; /* 左移 图片的一半 宽度*/
            margin-top:-65px;   /* 上移 图片的一半 高度*/
        }
    </style>
</head>
<body>
    <div style="width:300px;height:200px;border:1px solid #ccc">
        testtesretest
    </div>
    <div class="thumbBox">
        <img class="imgGoods" src="http://www.baidu.com/img/bdlogo.gif" />
    </div>

</body>
</html>

 

posted on 2013-08-11 18:44  马丁传奇  阅读(569)  评论(0编辑  收藏  举报