I'd like to place an blog entry title on an entry thumbnail image vertically aligned to middle.
An image size changes as window size changes and an blog entry title may be more than two lines depending on each blog entries.
I found this web-site that successfully place an text vertically aligned to middle of an image .
On the page below, you see three images with titles.
https://www.hyperisland.com/community
I read the code of the webpage above and try the code below, but it doesn't work as I expect.
This is the code I've got to so far.
http://codepen.io/anon/pen/kFwAH
HTML
<html lang="ja">
<head>
</head>
<body>
<div class="articleTitle">
<h1 class="title"><span>Article title. Artile title. Article Title.Article title.</span></h1>
<img src="http://placeimg.com/500/500/any" alt="">
</div>
</body>
</html>
CSS
.articleTitle {
background: #eee;
position: relative;
}
img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
z-index: 1;
max-width:100%;
}
h1 {
line-height: 1;
z-index: 2;
position: relative;
height: 100%;
text-align: center;
vertical-align: middle;
}
h1:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
h1 span {
display: inline-block;
vertical-align: middle;
}
Could anyone please help me out?
I'm new to CSS and I've been studying hard css lately.
Thanks!
note
- As I mentioned earlier, an image size changes as window size changes.
- an entry title may more than two lines. it depends on an article.
- it needs to be compatible to IE8 as well.
- I don't want to treat image as background of div.I want to use img tag in code.