Tips for dynamically resizing hover text descriptions in WordPress to accommodate varying lengths of text

Hey there, I've been struggling with making the text fit inside the hover effect of my image box in a WordPress post. Any suggestions on how to resolve this issue? I have provided a link to a screenshot where the problem is visible. Please take a look at my CSS code below and let me know if you see any issues. Thanks!

https://i.sstatic.net/onkhB.png

Below is the snippet of my CSS:

.top-featured-image {
    position:relative;
    width: 280px;
    overflow:hidden;
    display:inline;
}
.top-featured-image span {
    background-color: rgba(130,127,122,0.7);
    color:white;
    font-size: small;
    position:absolute;
    bottom: -97px;
    left:0px;
    padding-left: 5px;
    padding-right: 5px;
    max-height: 100px;
    width:300px;
    display: none;
    float:left;
    text-align:left !important;
}
.top-featured-image span a {
    color:white;
}
.top-featured-image span a:hover {
    color:white;
}
.top-featured-image ul {
    list-style:none;
    display: inline;
}

And here's a snippet from my HTML containing the WordPress post loop:

( $productsBlog->have_posts() ) : 
                ?>
<div class="container">
<ul class="image">
<div class="row row-centered">
    <?php while ( $productsBlog->have_posts() ) : $productsBlog->the_post(); ?>
        <div class="col-xs-4 col-box1" onMouseOver="show_title<?php echo $count ?>()" onMouseOut="hide_title<?php echo $count ?>()">
        <li class="top-featured-image">
        <span class="effect" id="hoverli<?php echo $count ?>"><?php the_content( sprintf('<a href="%s">', esc_url(get_permalink())),'</a>'); ?></span>
        <?php the_post_thumbnail('productsize'); ?>

        </div>
        <?php if($count==2) :
        echo '</div>';
        echo '<div class="row row-centered">';
        endif; ?>
        </li>
        <?php $count++; endwhile; ?>
        </ul>
        </div>


    <?php endif; 
    wp_reset_postdata();

Answer №1

Perhaps experimenting in the editor will help, have you considered using max-height: 100px;?

I find your css a bit confusing. I plan to test it out myself to confirm if it doesn't work. By the way, I recently worked on a project with this resource http://jsfiddle.net/51csqs0b/ - it might give you some ideas as well.

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

Is it possible for someone to assist me in making my map stay in a fixed position?

How can I make sure that my map stays in a fixed position on the screen even when the user scrolls? Here is the code snippet I am using: #map { float: right; height: 545px; width: 40%; margin-top: 12px; margin-right: 30px; posit ...

Is there a way to navigate to the "Error" view page following an AJAX request?

Currently, I am utilizing an Ajax function to call an HTTP Post Action method located in the controller. During this process, the action method is producing a basic exception message. To address this issue, I have applied my own personalized handler attr ...

What is the best way to use Javascript in order to automatically open a designated tab within SharePoint 2013?

Currently, I am in the process of developing a website project which incorporates Bootstrap tabs utilizing jQuery. While these tabs are functioning excellently on various pages, I am faced with the challenge of linking specific icons to corresponding tabs ...

Transferring data from an Excel spreadsheet into a structured table

I am interested in transferring specific columns of data from an excel sheet to an HTML table. My goal is to populate the table based on certain conditions rather than statically inputting fixed cells. For instance, if my excel sheet has columns for Name ...

Utilize a jQuery class selector to retrieve the value of a textbox through HTMLHelper

How can I retrieve the value of "StudentID" in a JavaScript function using jQuery? HTML: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Student.Models.vwStudent>>" %> <div class="divClass"> ...

Leverage PHP to retrieve the value from a jQuery div element

One of my <div id="single-home-container"></div> is showing a value generated by a jQuery script. Is there a way to utilize PHP in order to retrieve that value for the purpose of passing it into a MySQL query? Thank you. ...

Mastering the art of using jQuery AJAX in conjunction with JSP for efficient database updates

I've been working with ajax and jquery to call a jsp page that submits form data to a database. However, I'm encountering an issue where I receive a "Null values can't be inserted to database" exception when running the insert query. Oddly e ...

Extract the titles and showcase them in a div using a structured list

Currently, I have a dynamic container with the class .product_section where I need to display the headings inside it in a UL list format within the div.toc. I am looking for a script that can iterate through each .product_section and generate a list using ...

Using AJAX to upload an image and passing multiple parameters

I'm facing an issue when trying to upload an image along with other input text in a form and send it to ajax_php_file.php. Whenever I upload the image, all my input text fields appear empty. Any assistance would be greatly appreciated. Thank you very ...

The function $.ajax may not be available, but rest assured that the jquery library is functioning properly

Upon checking the console, I noticed the following: Here is the AJAX code snippet in use: $("#accept").click(function(){ id = $("#idInput").val(); password = $("#passwordInput").val(); alert(id) alert(password) $.aja ...

The hyperlink does not appear to be functioning properly within a specific Div on the iPad. Interestingly, this issue does not persist when using other

Apologies if I am posting this question in the wrong place. I have a webpage (built with asp.net/vb) where each section is contained in divs within a Bootstrap grid. Through the code behind, I am attaching onclick events to each set of divs to perform sp ...

Success in inserting PHP content achieved through JQuery modal overlay

Does anyone know how to implement a jQuery modal overlay that appears when an HTML form successfully inserts data into a database? For example, I want the modal overlay to say "Success!" if the data is inserted and "Sorry, your post was not uploaded." if ...

Transform SQL query into an array format

In my WordPress database, I am fetching records from tables using the code below... global $wpdb; echo '<table>'; $sellers = get_users('blog_id=1&orderby=nicename&role=sellers'); foreach ($sellers as $seller) { e ...

Unable to align two overlapping images centrally

https://i.sstatic.net/5Szut.jpg Two identical images are displayed correctly with a semi-transparent 'logo' on top of a base green image. However, they are positioned on the left and I need them both to be centered on the screen. I can't se ...

Exploring the world of child theme customization in WordPress

I am looking to make some modifications to my website. Working with a child theme, I have plans to adjust the CSS and make some structural changes. Modifying the CSS seems pretty straightforward as I just need to reference the classes or IDs and input new ...

How to include a CSS file in an HTML file without the need for webpack

I've encountered a challenge while working on my Electron project and using Electron-packager to package the app. The issue lies in the folder structure, where CSS files located in the parent folder of the Electron project/package.json are not gettin ...

Angular promise not waiting for the resolution to complete

It appears that I am still struggling to grasp the concept of promises. I am using angular resolve in an attempt to ensure that the view is not loaded before the promise resolves, but it doesn't seem to be working as expected. Can anyone point out wha ...

Arranging divs in a layout similar to tables cells and rows

Currently, I am developing a small game to enhance my Javascript skills. In the past, I utilized tables for displaying my content (images): Now, my goal is to switch from using tables to divs. However, I want to position them in a manner that resembles t ...

Following the content update via Ajax, the functionality of jQuery is experiencing glitches

My content slider works well on the first page of ajax loaded content. However, when I navigate to the next page from ajax loaded content and try to update the sliding animation for newly loaded future content using #readyslider, the slider starts glitchin ...

Upon each iteration, a new array must be generated using Jquery

When working with arrays in jQuery, I encountered an issue where the key and value were being added as an object instead of a new array or key within a loop. $.each($("input[type='time']"), function(){ var checkboxid = $(this).attr( ...