Struggling to align the Title Tags perfectly in the center of Images

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! :)

Answer №1

I'm not quite sure how to modify the script, but I managed to resolve the issue by executing the following commands in the chrome console.

  1. Eliminate the float right for elements under post-body.
  2. Adjust the positioning of the image itself.

The text is already centered; the problem lies in the arrangement of the elements.

Check out the screenshot -> boomlands

EDIT

     .postImage img {left: -6px; bottom: 10px;} 
     .post-body a {float:none;}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What separates text-align:center from margin auto?

As someone who is just beginning to learn about CSS, I have come across the properties: text-align:center; and margin:auto; Both of these seem to center elements, but how exactly do they differ from each other? Any insights would be much appreciated. T ...

Is there a way to invert the order of elements in a scrollable container in Google Chrome?

The code snippet provided creates the desired effect, but unfortunately, it only seems to function properly in Firefox and Edge. In Chrome, while the elements are stacked correctly, there is no horizontal scroll bar, making the rightmost items hidden and i ...

Having trouble retrieving data from the controller in JSON format

I am having trouble getting the data from the controller to the view in JSON format, and I can't figure out why it's not working. This is my controller (I request it on the index action): public class HomeController : Controller { ...

The captivating logo animation of Google Chrome

For optimal viewing experience, it is recommended to use Chrome or any WebKit browser. https://www.google.com/intl/en/chrome/browser/ Hovering over the chrome logo reveals an amazing effect. I tried downloading the page source, but got lost in it. The s ...

Parent and router-outlet in Angular 4 fashion

Suppose we are presented with the following code: <div class="container"> <div class="row"> <div class="col-sm-4 col-md-3"> <app-sidebar></app-sidebar> </div> <div class="c ...

Error: The parent selector "&" cannot be used in top-level selectors. $::webkit-input-placeholder

I am facing an issue while trying to run a legacy create-react-app that utilizes Sass. Initially, when I ran npm start, I encountered the error 'Cannot find module sass', which resembled the message found in this stack overflow post. To resolve t ...

Finding the data type based on the button clicked with javascript: A beginner's guide

I am trying to work with a PHP function that generates dynamically created divisions. Each of these divisions contains a different data type and a button. How can I extract the data type of a division when the user clicks on the submit button using JavaScr ...

Fancybox operates successfully when I manually include a class, yet fails to function when utilizing jQuery's .addClass() method

Below is a snippet of JS code that I use to add Fancybox classes to all hrefs on a webpage: $(function(){ //declaring target variable var $targetTable = $('.photo-frame a'); //looping through each table and adding the fancybox cla ...

Is nextJS SSR the optimal solution for handling undefined variables in the window object to enable optional chaining in cases where global variables are not supported?

When using (window?.innerHeight || 420) for server-side rendering (SSR), the translation would be (((_window = window) === null || _window === void 0 ? void 0 : _window.innerHeight) || 420) However, this could result in a referenceError: window is not d ...

"Interactive demonstration" image toggle through file upload

I have a project to create a "demo" website for a client who wants to showcase the template to their clients. A key feature they are interested in is allowing users to upload their logo (in jpg or png format) and see it replace the default logo image insta ...

Using AngularJS ui-router to implement Bootstrap UI tabs

Having trouble with Bootstrap UI Tabs in AngularJS ui-router. Trying to add an active class when refreshing the page. Passing the tab's URL to the asActive(url) function in my controller to compare with the current URL of the page. Using the "active" ...

Backstretch.js experiencing issues with element functionality, but functioning correctly with body element

I'm having trouble getting backstretch to work on a div. It works perfectly when applied to the body with no errors, but when I try to apply it to a <div>, I get this error: Uncaught TypeError: Object [object Object] has no method 'backs ...

What are the steps to effectively utilize the $filter('filter') function when filtering multiple columns with OR as the condition?

In my AngularJs Application, I have a collection of customers. var customers = [ { "Name": "Alfreds Futterkiste", "City": "Berlin", "Country": "Germany" }, { "Name": "Ana Trujillo Emparedados y helados", ...

steps for transferring a shallow copy of an array to a function

How can I adjust this code so that when I press each button, the console.log displays a different slice of the array instead of always showing me the last 20 elements? for (var i = 0; i < array.length; i++) { var b; var NewArr = []; ...

Using three.js to set the HTML background color as clearColor

How can I set the HTML background as clearColor using three.js? Here is the code snippet for three.js: // Setting up the environment var vWebGL = new WEBGL(); var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(75, window.innerWidth / ...

The best way to consistently execute setTimeout in order, regardless of the timing, is by utilizing a Promise

I have the following code snippet: var timeOne = new Promise(function(resolve,reject) { setTimeout(function(){ console.log('This is one'); }, Math.random() * 1000); }); var timeTwo = new Promise(function(resolve,reject) { s ...

Ways to create a table with columns from various fields obtained through an API call

Looking to preprocess data received from an API, the raw data is structured as follows: https://i.sstatic.net/a9Q2Z.png Desiring to dynamically generate a table with columns based on the fields task_name and saved_answers. It's important to note tha ...

Problem with Bootstrap-slider not loading correctly

I seem to be facing an issue with selecting DOM elements that are part of bootstrap-slider. When I try to target them with events like click, nothing happens. All events work fine when the page is refreshed. What could be causing this problem? $(document ...

Twilio Group MMS feature experiencing technical difficulties

I currently have a Twilio Trial account with an active number that supports SMS/MMS. My goal is to use this number for group MMS chats, but I am facing some challenges. After following a tutorial on Tut, I attempted to create a basic test using the provid ...

What causes the disappearance of connecting lines after pushing content into a tab?

I have been using a jquery-connections framework to establish connections between elements on my webpage. However, I encountered an issue where the connectors disappear whenever I insert content inside the Tab. Upon including the following code: <div ...