vertical center an image without knowing dimensions

后端 未结 6 786
爱一瞬间的悲伤
爱一瞬间的悲伤 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:13

    You could use this CSS on your parent:

    #parent {
        display:table-cell;
        vertical-align:middle;
    }
    

    Note that this will make the parent element behave like an inline element.

    Example.

提交回复
热议问题