When attempting to center align images and their post titles, I encountered an issue where the left part of the image and title were being cut off by a small margin. Despite trying various methods, I was unable to successfully center the title tags. You can view the site here, where the images and titles were intended to be centered using the following script:
<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!
**/
$(document).ready(function() {
// Change the dimension variable below to set the maximum pixel width for the grid elements
var width = 190;
var height = 190;
// Placeholder image in case a blog post does not have an image
var placeholder = 'http://lh5.googleusercontent.com/-bY-qeacmAlA/UI_98V9I9WI/AAAAAAAAGWc/8FzFSGYaj3o/s270/placeholder.jpg';
// Grid margins such as 5px
var margins = "15px 2px 5px 2px";
// Set 1 for squared image or 0 for proportional,
// highly recommend squared for proper display
// squared images only work for images hosted in Picasa
var square = 1;
// Style info for the area where the post title will be displayed
var altBackground = "#000000";
var altTextColor = "#ffffff";
var altPaddingTop = 15;
var altPaddingBottom = 20;
var altPaddingSides =5;
var paddingString = altPaddingTop + 'px ' + altPaddingSides + 'px ' + altPaddingBottom + 'px ' + altPaddingSides + 'px';
$('.post-body').each(function(n, wrapper){
var wrapper = $(wrapper);
var image = $(wrapper).find('img').first();
var link = wrapper.parent().find('h3 a');
var linkURL = link.attr('href');
var linkTitle = link.text();
$(link).remove();
wrapper.empty();
if (image.attr('src')) {
var imageOriginalHeight = image.attr('height');
var imageOriginalWidth = image.attr('width');
var imageParent = $(image).parent();
wrapper.append(imageParent);
if (square) {
image.attr({src : image.attr('src').replace(/s\B\d{3,4}/,'s' + width + '-c')});
image.attr('width',width).attr('height',height);
} else {
image.attr({src : image.attr('src').replace(/s\B\d{3,4}/,'s' + width)});
image.attr('width',width);
var newHeight = (imageOriginalHeight/imageOriginalWidth * width).toFixed(0);
image.attr('height',newHeight);
}
} else {
var image = $('<img>').attr('src',placeholder).attr('height',height).attr('width',width);
var imageParent = $('<a>').append(image).appendTo(wrapper);
}
imageParent.attr('href',linkURL).css('clear','none').css('margin-left','0').css('margin-right','0').addClass('postImage');
var imageAlt = $('<div>').prepend(linkTitle).css('padding',paddingString).css('color',altTextColor).css('background-color',altBackground).css('opacity','0.9').css('filter','alpha(opacity=90)').css('width',width).appendTo(imageParent);
var divHeight = imageAlt.height();
var sums = parseInt(divHeight) + parseInt(altPaddingTop) + parseInt(altPaddingBottom);
imageAlt.css('margin-top','-'+sums+'px');
wrapper.css('float','left').css('height',height).css('width',width).css('margin',margins).css('overflow','hidden');
});
$('#blog-pager').css('clear','both');
});
function killLightbox() {
var images = document.getElementsByTagName('img');
for (var i = 0 ; i < images.length ; ++i) {
images[i].onmouseover=function() {
var html = this.parentNode.innerHTML;
this.parentNode.innerHTML = html;
this.onmouseover = null;
};
}
}
if (window.addEventListener) {
window.addEventListener('load',killLightbox,undefined);
} else {
window.attachEvent('onload',killLightbox);
}
//]]></script>
<style>
a.postImage div {
display: block;
} a.postImage:hover div {
display: block;
}
h3, .post-footer {
display: none;
}
h2{display: none;}
</style>
This modified script above, with the original script available here. To test your modifications, you can use the Stylebot app extension in Chrome or other browsers. Thank you in advance! :)