0

I cannot for the life of me figure out how to get the caption text centered when the image is hovered. I tried vertical align and specifying it as inline block, playing around with different positioning. I feel like I'm missing something obvious.

https://jsfiddle.net/b5tmndvk/2/

HTML

<div class="container">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <div class="unit-thumbnail">
        <img src="http://i.imgur.com/yIKP2YB.jpg?1" width="100%">
        <div class="unit-caption">
          <p>Updoot this Stack Overflow post and help me figure this out.</p>
        </div>
      </div>
    </div>
  </div>
</div>

CSS

.unit-thumbnail {
    position:relative;
    overflow:hidden;
}

.unit-caption {
    position:absolute;
    bottom:-100%;
    right:0;
    background:rgba(37, 139, 202, 0.75);
    width:100%;
    height:100%;
    padding:2%;
    text-align:center;
    color:#fff !important;
    z-index:2;
    -webkit-transition: all 0.9s ease-in-out;
    -moz-transition: all 0.9s ease-in-out;
    -o-transition: all 0.9s ease-in-out;
    -ms-transition: all 0.9s ease-in-out;
    transition: all 0.9s ease-in-out;
}
.unit-thumbnail:hover .unit-caption {
    bottom:0%;
}

1 Answers1

0

add this css

.unit-caption p{
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

https://jsfiddle.net/b5tmndvk/3/

Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40