For a long time I've been disappointed with the way most content management systems provide image captions in their WYSIWYG editors. Many, including Blogger, create an old-school table wrapped around the image, put the image in the first table row, then add the caption text into the second table row. You might have the most HTML 5, up to date website, and then suddenly you're stuck using tables like it's 1998.
We believe we've created a method that is both slick and interactive, as well as quite possibly increasing your search engine performance and making your images Section 508 accessible! It involves using your image's ALT text, some JQuery, and hovering over the image (optional), and we think it's pretty cool.
Step #1: adding alt text to your images
A while ago Blogger added the ability for bloggers to add alt text to their images as well as title text to the link surrounding the image. This functionality was never heralded, simply wrapped into the larger updates of SEO, permalinks, etc. Because of this many users still are not aware of this functionality and I'm guessing only a tiny percentage of users take advantage of it.
Head to your blog post and edit the post in the Compose tab. Click on the image in your post to open the dialog options that are displayed under your image, the ones where you normally set the size or placement of the image (or even the caption). Click on "Properties" (I know, you probably have overlooked this dozens of times).
A dialog window is now displayed where you can set the title text of the image's wrapping link, or you can set the alt text. We're going to use the alt text for our purposes. Put in your caption as the alt text and hit OK.
Save your post updates.
Step #2: the JQuery code
You can access a clean version of the code here.
<script language='javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js' type='text/javascript'/>
<script type='text/javascript'>//<![CDATA[
/**
this script was written by Confluent Forms LLC http://www.confluentforms.com
for the BlogXpertise website http://www.blogxpertise.com
any updates to this script will be posted to BlogXpertise
please leave this message and give credit where credit is due!
**/
var altBackground = "#ffffff";
var altTextColor = "#000000";
var altPaddingTop = 5;
var altPaddingBottom = 8;
var altPaddingSides = 5;
$(document).ready(function(){
$('.post-body').find('img').each(function(n, image){
var image = $(image);
var alt = image.attr('alt');
var id = image.index();
var imageAltId = 'imagealt'+n;
image.parent().addClass('postImage');
var paddingString = altPaddingTop + 'px ' + altPaddingSides + 'px ' + altPaddingBottom + 'px ' + altPaddingSides + 'px'
image.after($('<div>').css('padding',paddingString).css('color',altTextColor).css('background-color',altBackground).css('opacity','0.6').css('filter','alpha(opacity=60)').attr('id',imageAltId).text(alt));
var divHeight = $('#'+imageAltId).height() + altPaddingTop + altPaddingBottom;
$('#'+imageAltId).css('margin-top','-'+divHeight+'px');
});
});
//]]></script>
<style>
a.postImage div {
display: none;
} a.postImage:hover div {
display: block;
}
</style>
What we're doing in this script is dynamically grabbing the alt text from the image (that you added in Step #1), creating a new div after the image but inside the link, inserting the alt text into that div, and then only displaying it when you hover over the image.
To use this code you need to insert it into your template before the /head tag. You can wrap it within the standard if/else statements so it only operates on certain pages or types of pages, and you can customize the CSS in the style information area included in the code sample.
To see an example of this code in action please visit this demo page (the first image)
Enjoy!
Popular
-
Tip: Resize your thumbnails in Blogger's Popular Posts widgetA common frustration, and one we too shared, was the limited sizes that thumbnail images can be dis…
-
Website redesign launch of Concentrics Restaurants!This week we're proud to announce the launch of the website redesign for Concentrics Restaurant…
-
Tip: Making index page images link to the post pageThis tip mainly applies to blogs that take advantage of jump breaks in their posts as a way to shor…
-
Hangout on Air: Friday Request Line for 10/19/2012Less is more, user-centric design, focusing on your user experience, and lots of template manipulat…
-
Question: Can I use my own domain name with my Blogger site? Will hosting still be free?Coming across a blog that is using a blogspot.com address, like yourblog.blogspot.com , tells us on…
-
Tip: Creating a newspaper layout in Blogger with the first image before the articleA request that often is brought up in Blogger development forums is the desire to break the convent…
-
Tip: Better titles for your article posts and pagesOne of the simplest ways you can improve your Blogger site's search engine optimization (SEO), …


Post a Comment
Post a Comment