Implementing both fancybox and a hover remove icon functionality on a single image

I came across a solution on this question here, outlining how to implement an overlay hover remove icon on thumbnails. I tried incorporating it into my page, along with fancybox, but unfortunately, I'm encountering issues getting both functionalities to work simultaneously. The problem seems to stem from the fact that they both require the use of the <a> element.

This is what my current code looks like:

<div class="image-thumb" style="display: inline-block; background-image: url('<?php echo base_url().$path.$thumb; ?>');" align="center">
<a class="fancybox" href="<?php echo base_url().$path.$file->filename; ?>" rel="galery1" title="<?php echo $file->description; ?>">
    &nbsp;
</a><br>
<?php echo $file->description; ?></strong>
</div>

The CSS associated with the implementation is as follows:

.image-thumb { 
position: relative; 
width: 150px;
height: 150px; 
background: transparent url() no-repeat center center;
}

.image-thumb a { 
display: none;
position: absolute; 
top: 2px;  
left: 126px; 
width: 22px; 
height: 22px; 
background: transparent url('/path/to/remove-icon.gif') no-repeat 0 0;
}   

.image-thumb:hover a { 
display: block;
}

Upon experimenting with the <a> element by setting the class to either fancybox or removing it altogether, I observed that only one of the functionalities would work at a time. I'm currently feeling stuck and seeking assistance in resolving this issue. Any suggestions would be highly appreciated.

Answer №1

...Because they both require the presence of the <a> element

In fact, you have the flexibility to attach fancybox to any HTML element besides <a> by utilizing the special fancybox attributes data-fancybox-*. Simply remove the fancybox class from your <a> tag and add it to the parent

<div class="image-thumb fancybox"...

Then, ensure that the href, title, and group attributes are properly set up like so:

<div class="image-thumb fancybox" data-fancybox-href="<?php echo base_url().$path.$file->filename; ?>" data-fancybox-group="gallery1" data-fancybox-title="<?php echo $file->description; ?>" style="...">
    <a>&nbsp;</a><strong><?php echo $file->description; ?></strong>
</div>

For a visual representation, check out this JSFIDDLE

Answer №2

Could you please attempt the following:

.image-thumb a.fancybox { 
display: none;
position: absolute; 
top: 2px;  /* position in bottom right corner, assuming image is 16x16 */
left: 126px; 
width: 22px; 
height: 22px; 
background: transparent url('/path/to/remove-icon.gif') no-repeat 0 0;
}   

.image-thumb:hover a.fancybox { 
display: block;
}

Make sure to use "fancybox" as the class name for your a element.

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

Enhance your scheduling capabilities with FullCalendar2's customizable minTime and maxTime settings for each

Can each weekday have different minTime and maxTime in fullcalendar (the hours on the left side)? For example: Monday: 08:00 - 18:00 Tuesday: 08:00 - 18:00 Wednesday: 10:00 - 19:00 Thursday: 13:00 - 20:00 ... The default setting in fullcalendar appl ...

What are the steps to build a dynamic webpage in a Django project?

For my Django app, I have successfully created static pages without any ajax requests. However, I now want to add a dynamic subpage that can change its content without refreshing or reloading the entire page. Let me explain what I'm trying to achieve ...

Is it possible to use CSS and HTML to rotate a cube and expand its sides?

I am attempting to rotate the cube and expand its faces. I have experimented with the following code: .wrapper{ position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); } .cube-wrap { width: 40px; height: 40px; ...

What is the best way to select a clicked span element within a div using JQuery and then adjust the spans before and after it

<div> <span>A</span> <span>B</span> <span>C</span> <span>D</span> </div> If a user clicks on one of the spans within the div, I want to apply styles (such as text color) to that span and all prec ...

Conditional jQuery actions based on the selected radio button - utilizing if/else statements

This task seemed simple at first, but I quickly realized it's more challenging than expected. Apologies in advance, as Javascript is not my strong suit. My goal is to have the main button (Get Your New Rate) perform different actions based on whether ...

Utilizing Ajax, Jquery, and Struts2 for File Uploading

Can someone please provide guidance on uploading files using a combination of Ajax, jQuery, and Struts2? I have searched through numerous tutorials online but haven't found a suitable solution yet. The goal is to trigger a JavaScript function when a b ...

Incorporate a website link into an isotope filter

My filter configuration is as follows: <ul class="filters filter-portfolio"> <li><a href="#" class="selected animated" data-animation="fadeInUp" data-filter="*">All</a></li> <li><a hre ...

Mobile devices not showing the Navbar bootstrap menu

My header.php works perfectly on desktop, but the navigation bar is not displaying properly on mobile devices. Here is my code: <!DOCTYPE html> <html> <head> <title>International Pvt. Ltd.</title> <meta name="viewpo ...

Decrease the size of the hyperlink area to only the center portion of the text for a more precise click target

Normal text links are present: <a href="projects.html">Projects</a> Is it feasible to make only the middle part of the letters clickable? Such as excluding the top of 'P' or the bottom of 'j'? a { font-size: 50px; ...

Encountering an unexpected token error while attempting to incorporate JQuery into a React JS project

I am currently diving into the world of React.js and attempting to incorporate a side navigation bar on my homepage. However, I encountered an eslint error when trying to implement the sidebar using jQuery code. Below you will find the code snippet for the ...

What's the best way to invoke a function from a different JS file or create a custom event in JQuery that includes a parameter as a data object?

I am facing an issue while using requireJS to call a function from a required JS file. In my main app.js "controller", I have included (plugin)app.js, which contains all plugin configurations and related functions. The snippet below is from app.js defin ...

What is preventing this jQuery from altering the opacity?

Currently, I have a piece of code that is intended to change the opacity of a div element from 0 to 1 as soon as the user initiates scrolling on the body. However, it appears to be malfunctioning for reasons unknown. $("bod").load(function(){ document ...

Integrate blogger into my website with automatic height adjustment and scrolling functionality

Check out my website here. I've integrated a blogger component into it. Can anyone provide guidance on creating parallel scroll and automatically resizing sections based on the blog's height? Thanks, M ...

Tips for generating a unique identification for every blog post

Trying to use jQuery's "prependTo" function to move the post image from one div element to another. Check out the fiddle for more details. $('.post img').prependTo('.move'); Since a class selector is used, each image will be move ...

Exploring the power of nested styled components in Material UI is a great way to elevate the styling of your project

Can someone explain how to access a second styled component using '@mui/system' in order to add a hover effect to a parent element that will modify the max-height of its child? Please keep in mind that I am referring to mui's styled compone ...

Determine whether to show or hide a div based on the width of the

Is there a way to dynamically hide a div using Bootstrap 4 based on the screen width? Can this be achieved without using JavaScript? I am particularly interested in hiding certain text elements that are not relevant on smaller screens, such as mobile de ...

If tall, then the height is set to 100%; if wide, then the width is set

My image-generating algorithm produces images of various sizes, some tall and some wide. How can I ensure that the images always fit perfectly within their parent container? They should be 100% height if they are tall and 100% width if they are wide. .im ...

Is it possible to retrieve local variable JSON arrays using ajax/getJson()?

When starting a project without a database or data source, I often create json arrays in a *.js file to populate screens until the data modeling or database creation is complete. I am trying to figure out how to write an ajax/getJson() function to access ...

File uploads in Django may pose a challenge when the request is sent from Ajax along with a form

I'm facing an issue while attempting to upload a file in Django using Ajax post. Unfortunately, it doesn't seem to work as expected. Here is the HTML code snippet responsible for handling the upload: <form action="{% url 'saveprof' ...

Create a copy of an element without altering the original

Currently, I am attempting to create a duplicate of a class and ensure that it remains unaffected when the original is altered. So far, I have tried: $(".newclass").addClass("oldclass"); However, this method does not copy the content. var _elementClone ...