使当前对象相对于上层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>

 

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-12-01
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-02-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案