Tips for placing an icon on top of a thumbnail

My php skills are not the greatest and I'm new to wordpress. I have a custom post type for books that displays all the books in my archive-library.php file with titles and thumbnails.

I am looking to add a fading icon when hovering over the thumb. Here is an image showing the issue: https://i.sstatic.net/d9ZpI.png and here is the HTML code that renders in developer tools

<div class="lib-style" style="">
    <a href="http://localhost/royayeketab/book/mostafamastoor-2/">
    <img width="1012" height="1181" src="http://localhost/royayeketab/wp-content/uploads/2016/08/movafaghiyat.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="movafaghiyat" srcset="http://localhost/royayeketab/wp-content/uploads/2016/08/movafaghiyat.jpg 1012w, http://localhost/royayeketab/wp-content/uploads/2016/08/movafaghiyat-257x300.jpg 257w, http://localhost/royayeketab/wp-content/uploads/2016/08/movafaghiyat-768x896.jpg 768w, http://localhost/royayeketab/wp-content/uploads/2016/08/movafaghiyat-877x1024.jpg 877w" sizes="(max-width: 1012px) 100vw, 1012px">
    <span class="dis-lib-more">

    </span>
</a>
<p class="text-center">موفقیت پنج</p>
</div>

This is the code I currently have:

<?php $args = array( 'post_type' => 'book'); 
    $loop = new WP_Query( $args ); ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <div class="lib-style" style="">
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail(); ?>
                <span class="dis-lib-more">
                </span>
            </a>
            <p class="text-center"><?php the_title(); ?></p>
        </div>
    <?php endwhile; // End of the loop. ?>

CSS style:

.lib-style{
    display: inline-block;
    text-align: center;
    padding: 10px 10px;
    /*margin-bottom: 25px !important;*/
}
.lib-style p{
    margin-top: 10px;
}
.lib-style a{
    display: inline-block;
    background:#000;
}
.lib-style img{
    display: block;
}
.lib-style:hover img{
    opacity: 0.5;
    -webkit-transition: all 0.5s linear;
    -moz-transition: all 0.5s linear;
    -ms-transition: all 0.5s linear;
    -o-transition: all 0.5s linear;
    transition: all 0.5s linear;
}
.dis-lib-more{
    display: none;
    width: 50px;
    height: 50px;
    background-image: url('images/mag.png');
}
.lib-style:hover span{
    display: block;
    -webkit-transition: all 0.5s linear;
    -moz-transition: all 0.5s linear;
    -ms-transition: all 0.5s linear;
    -o-transition: all 0.5s linear;
    transition: all 0.5s linear;
}   

Any suggestions would be greatly appreciated.

Answer №1

It seems like you're looking to position the dis-lib-more element on top of the thumbnail. If that's what you need, you can achieve this by adjusting the left and bottom properties in the following CSS snippet:

.lib-style a {
    position: relative;
    /* Your original CSS goes here.... */
}

.dis-lib-more {
    position: absolute;
    bottom: 0;
    left: 0;
    /* Your original CSS goes here.... */
}

Here's an example:

.lib-style {
  display: inline-block;
  text-align: center;
  padding: 10px 10px;
  /*margin-bottom: 25px !important;*/
}
.lib-style p {
  margin-top: 10px;
}
.lib-style a {
  position: relative;
  display: inline-block;
  background: #000;
}
.lib-style img {
  display: block;
}
.lib-style:hover img {
  opacity: 0.5;
  -webkit-transition: all 0.5s linear;
  -moz-transition: all 0.5s linear;
  -ms-transition: all 0.5s linear;
  -o-transition: all 0.5s linear;
  transition: all 0.5s linear;
}
.dis-lib-more {
  position: absolute;
  bottom: 0;
  left: 0;
  display: none;
  width: 50px;
  height: 50px;
  background-image: url('http://placehold.it/45x150');
}
.lib-style:hover span {
  display: block;
  -webkit-transition: all 0.5s linear;
  -moz-transition: all 0.5s linear;
  -ms-transition: all 0.5s linear;
  -o-transition: all 0.5s linear;
  transition: all 0.5s linear;
}
<div class="lib-style" style="">
  <a href="<?php the_permalink(); ?>">
    <img src="http://placehold.it/150x150" alt="">
    <span class="dis-lib-more"></span>
  </a>
  <p class="text-center">Some text here</p>
</div>

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

The FaceBook modal is failing to appear

Attempting to implement FaceBook Login through a modal. Upon clicking the button below, the FaceBook Login Modal should appear. <li> <a href="#sign-in-dialog" class="login sign-btn" title="Sign In">Sign In</a> </li> The HTML co ...

Dynamically filling the text area by fetching data from the database when a dropdown option is selected

There is a table called 'vendortable' with attributes 'vendorid', 'vendorname', and 'vendoraddress'. I am struggling to populate the data from the database into a textarea using jQuery and AJAX. Calling all amateu ...

Switch the dropdown icon in ng-bootstrap when clicked

Click me to switch icon from fa-angle-up to fa-angle-down. Initially displaying the fa-angle-up icon, clicking it will change it to fa-angle-down. <div class="col text-right"> <div ngbDropdown placement="top-right" class="d-inline-block"> ...

Dynamic class name changes in Angular.js based on JSON object

I am trying to dynamically change the class of an <li> element based on the category value I am getting, but for some reason the class name won't update. Here is the code snippet: <div id="content"> <ul id="container" ng-controller ...

Choose a div element based on its title attribute using jQuery

My webpage includes a div that holds multiple other divs without unique IDs assigned to them: <div id="container"> <div title ="jhon" style=" position:absolute; left: 821px; top: 778.44px; width:8px; height:9px; z-index:3;"> </div> < ...

What steps should I take to troubleshoot this file uploading error on my Mac?

Caution: The file upload for "Kol auto.png" failed to open due to permission issues at line 56 in /Applications/XAMPP/xamppfiles/htdocs/selfsub/one.php Error: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpa6Q0J9' to 'upload/Kol aut ...

Looking for a particular table element using Selenium Webdriver in Java: A Guide

After locating a table element using this: WebElement tableElement = selectorboxelement.findElement(By.xpath("//ancestor::table")); I identified the `selectorboxelement` as a web element with this line of code: WebElement selectorboxelement = driver.fin ...

The jQuery ellipsis extension is incompatible with the "max-height" property

Is it possible to use this plugin with the "max-height" css property? Currently, it only works with a specific height defined but not with max-height. Is there a way to make it compatible with max-height as well? (function($) { $.fn.ellipsis = f ...

Tips for incorporating multiple choices on the PayPal checkout page or creating a dedicated page for various options

I am seeking guidance on how to offer multiple donation options on a checkout page. Imagine a non-profit organization with several different programs. They want to provide users the opportunity to donate to specific programs, in varying amounts, all at on ...

Button that toggles colors

I tried creating a JavaScript code that would change the background color of the body when a button is clicked. However, when I checked the console, it showed an error saying that body.style.background is not a function. Can someone help me identify the ...

Menu within a menu, accessed by hovering

<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <a href="index.html" class="navbar-brand display-4">NintendoWorlds</a> <button class="navbar-toggler" dat ...

Should PHP be avoided in CSS files?

I've recently developed a CSS page named style.php and at the beginning, I included this line: <?php header("Content-type: text/css"); ?> What are your thoughts on this approach? Is it considered a bad idea? The reason behind doing this is tha ...

Bespoke Video Player using HTML5 with "Nerdy Stats" Feature

I have been given the task of creating a streaming video testing framework for internal metrics and measurement purposes. Essentially, I am looking to develop an HTML5 player that can handle streams and provide performance data related to: - Average Bitr ...

AJAX - Retrieving the server response following a page change by the user

My Understanding: I comprehend that when I make an ajax call to my server, a handler is created, the request is sent, my PHP script receives and processes the request, and sends back a response which my JavaScript can parse. Additionally, I am aware that ...

On certain websites, the footer may appear distorted or incorrectly displayed when viewed in the IE 9 web browser

Currently experiencing an issue with the display of the footer in IE9. On some pages, the footer is not properly fixed and overlaps the middle of the content. However, this problem does not occur when using other web browsers. Here is the code that I am c ...

dynamic field selection in Rails forms

In my Rails 3 project, I am using nested_form which allows users to dynamically add or remove fields. However, I am struggling to find the jQuery selector for these dynamic fields in order to perform some JavaScript calculations between them. Currently, ...

What are the steps to creating a live editor for the plugin settings page in WordPress?

As the creator of the WordPress plugin Tipu Scroll To Top, I am seeking assistance on how to enable users to view live changes on the setting page. Currently, my implementation only utilizes jQuery for the scroll to top button, which is shown below: (func ...

Invoke the Bootstrap function from a webpage

I am attempting to call an AngularJS function, but I keep receiving an error that says "Cannot read property 'forget' of undefined." Can someone please help me resolve this issue? Below is the JavaScript code I am using: var rootApp = angular.m ...

Utilizing the content of an HTML element within Ruby embedded code - a comprehensive guide

Below is the code snippet in question: <% @groups.each do |group| %> <tr> <td id="groupid"><%= group.id %></td> <td><a href="#dialog" name="modal"><%= group.title %></a></td> </tr> &l ...

What is the best way to combine multiple data variables using jquery?

fetchUserData(function (userData) { userData.forEach(function (user) { let userUsername = typeof user.username; let userAge = typeof user.age; }); }); console.log in browser: ("{\"data\":{\"userDataL ...