vertical center an image without knowing dimensions

后端 未结 6 700
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 03:04

I have centered a lot of stuff in my webdevelopment career, but I was wondering if there is a simple way to centering an image vertically without knowing the image\'s dimens

6条回答
  •  不知归路
    2021-01-19 03:21

    You can use this:

    #wrapper{    
    height: 100%;
    min-height: 500px;/*Assuming min-height of the container*/
    position: relative;
    width: 100%;}
    
    #parent{    
    border: 1px solid;
    height: 50px;
    position: absolute;
    top: 50%;
    width: 50px;}
    

    Check this in fiddle too http://jsfiddle.net/kYgqx/2/

提交回复
热议问题