Henrik Albrechtsson Henrik Albrechtsson - 1 year ago 107
CSS Question

Responsive vertical center with overflow hidden

After searching both Stack Overflow and Google I still wonder how to vertical center a image that is bigger than it's parent element. I use no height, just max-height, because I want to make a responsive solution, without jQuery. If possible.

Here is some code:

<div style="max-height: 425px; overflow: hidden;">
<img src="http://img.youtube.com/vi/jofNR_WkoCE/maxresdefault.jpg">

Answer Source

to center vertically an bigger image u can use the construction and css bellow

<div class="img-wrapper">
    <img src="http://img.youtube.com/vi/jofNR_WkoCE/maxresdefault.jpg">

And css:

    position: relative;

.img-wrapper img{
    position: absolute;
    top:-100%; left:0; right: 0; bottom:-100%;
    margin: auto;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download