Lately at Super­pos­i­tion Kitty we’ve been adopt­ing more of a photo-blog feel to some of our posts. If you’re recently read Apple Crumble The Retarded Way then you would’ve noticed that text is dis­played in a cap­tion inside the image when you mouse over it. The ori­ginal idea for this was taken from The Guard­ian web­site, where if you hover over any images on the main page a cap­tion will dis­play giv­ing you more inform­a­tion on the linked story.

I spent hours com­ing up with what I thought would be the most per­fect solu­tion to this (I didn’t want any of the extra JavaS­cript effects that The Guard­ian used), but my approach turned out to be too nar­row — work­ing only in Fire­fox. So I turned to my good old friend Google, and star­ted search­ing. I even­tu­ally came up with this CSS On-Hover Image Cap­tions tutorial by Soh Tanaka. Being pure CSS and work­ing in all browsers (includ­ing Inter­net Explorer 6 and 7) it seemed to be exactly what I wanted. You can view a page demon­strat­ing how his ver­sion works here, and I recom­mend that you read through his post first to get a greater idea of how these little CSS tricks achieve such an effect. Read on past the demo image below to see how you can get this up and run­ning on your blog.

The very first thing we’re going to do is cre­ate a CSS file. I try and con­tain most of my CSS files in their own folder, and have thus cre­ated a file named hover.css in /wp-content/themes/mytheme/css/, which will then be filled with my cus­tom­ised ver­sion of Soh Tanaka’s code as below:

.imgteaser {
padding: 0px;
margin: 0px;
margin-bottom: 18px;
overflow: hidden;
float: left;
position: relative;
}

.imgteaser a {
text-decoration: none;
margin-top: -18px;
float: left;
}
.imgteaser a:hover {
cursor: pointer;
}

.imgteaser a img {
float: left;
margin-bottom: 0px;
border: 1px solid #FDFDFD;
}

.imgteaser a:hover .desc {
display: block;
font-size: 12px;
line-height: 18px;
font-weight: normal;
color: #FDFDFD;
position: absolute;
bottom: 1px;
left: 1px;
padding: 0px 3px 0px 3px;
margin: 0;
width: 454px;
background: #000;
filter:alpha(opacity=80);
opacity:.80;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
}

.imgteaser a .desc {	display: none; }
.imgteaser a:hover .more { visibility: hidden;}

If you want more inform­a­tion on what each bit of CSS does, then once again I’d recom­mend read­ing the ori­ginal post. This file then has to be linked in the header of your Word­Press theme, so make sure to put the code below between the <head> and </head> tags (chan­ging as necessary):

<link rel="stylesheet" href="http://yourwebsite.com/wp-content/themes/yourtheme/css/hover.css" type="text/css" media="screen" />

It really is as simple as that! Now whenever we want to dis­play one of these beau­ti­fully cap­tioned images we can just modify the code below when writ­ing a new post (make sure that you are writ­ing in HTML Mode and not Visual Mode):

<div class="imgteaser">
<a href="#">
<img src="IMAGE LINK" />
<span class="desc">TEXT</span>
</a>
</div>

To see an example of this in action, simply scroll back up to the top and move your mouse over the pic­ture of the bike.


Leave a Reply

Details

'CSS Image Caption Rollovers For WordPress' was posted on September 14th, 2009 in the Category: Tutorials.

You can subscribe to the comments on this post, or post a comment of your own



Related Posts