Div内部的中心图像(垂直和水平)

时间:2013-03-12 18:42:49

标签: html css

我有一个容器div,我想在里面显示一个图像。图像将是动态的。它的尺寸可能大于/小于div的尺寸。我想在这个div中心(水平和垂直)显示整个图像。我该怎么做?

我读过很少类似this one的问题。但是,鉴于图像尺寸已知,大多数人都会谈论如何做到这一点。此外,我有水平居中工作,边距设置为自动。


编辑:到目前为止,添加我的CSS样式,库容器是更大的div,照片容器是包裹图像的那个。

    /* Gallery */
    #gallery-container { 
        position:absolute; 
        overflow:hidden;
        width:100%; 
        height:100%; 
        top:0; 
        left:0; 
        display:none; 
        z-index:100; 
        text-align: center;
   }


   #gallery-container .gallery-photo-container{
       position: relative;
       width:80%; 
       height:100%;
       margin: auto auto;
   }

   #gallery-container img{
       position: relative;
       max-width:100%; 
       max-height:100%;
   }

0 个答案:

没有答案