1

We have a container with known size.

Inside, we have content with unknown height.

We need to contain that content in the container while centered horizontally and vertically.

The content consists of blocks: label, image, label:

enter image description here

I managed to accomplish this for content shorter than the container, however no luck in the other case. Example: http://jsbin.com/banava/4/edit?html,css,output

Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125

1 Answers1

1
#content-wrapper {
    text-align: center;
    height: 200px;
    width: 200px;
    display: table;
}

#img-wrapper {
    width: 100%;    
    height: 100%;
    vertical-align: middle;   
    display: table-cell;
}

#img-wrapper label {
    display: block;  
    height: 25px;
    line-height: 25px;
}

#img-wrapper img { 
    max-height: 150px;
}

http://jsfiddle.net/L38jg9sr/15/

Leggy
  • 682
  • 7
  • 20