I'm facing an issue with aligning h2 text vertically in the middle of a block.
The situation is that I have multiple images with different heights but the same width (300px), each with varying amounts of text that may span over several lines and appear on top of the image when hovered over.
My goal is to vertically center this text...
Here's a demo:
http://jsfiddle.net/wn3Kj/2/
<div class="post-thumb">
<a href="http://eclectivism.com/text/">
<h2 class="entry-title">Text text text text text text text text text text text text text text text text text text text text text text text</h2>
<img src="http://eclectivism.com/wp-content/uploads/2013/09/space-doodle-01-580x7041.jpg" class="attachment-blog-large wp-post-image" />
</a>
</div>
CSS
.post-thumb {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent; }
a {position: relative; display: inline-block; }
h2 {
opacity: 0;
padding-right: 20px;
padding-left: 20px;
padding-bottom: 0px;
padding-top: 50%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
background: rgba(214,238,219,0.8);
color: #fff;
text-decoration: none;
text-shadow: 0px 1px 5px rgb(63, 97, 56);
text-align:center;
display:block;
}
img {
width: 300px;
}
a:hover h2 {opacity:1}