How can I create a smaller clickable zone inside a div element?

My task is quite intricate.

To begin, I have a hidden wrapper div that fades in when the mouse hovers over it and fades out when the mouse moves away. The next step is to include an image div inside the wrapper div. This image div, larger than the wrapper, must overflow its boundaries so that the entire image is visible and also fades in upon hover.

However, I am facing some challenges:

1. The image only overflows to the bottom left corner when hovered over.

2. The image appears when hovering over any area it covers, not just the wrapper area.

Desired result for issue 1: I aim to position the image within the wrapper so that it overflows in all directions. When hovering over the wrapper, I want the image to completely eclipse the wrapper, essentially centering the wrapper within the image.

Desired result for issue 2: I want the fade-in effect to be activated only when hovering over the 20 x 20 wrapper area. Hovering over the area covered by the image should not trigger the effect. On mouse off, the fade-out can start either when leaving the image or the wrapper area.

I could easily use a trick where one image fades out to reveal another, but I need the fade activation location to be within the fading area itself.

Isk


UPDATE:

Resolved issue number 1.

Now, I need to address my second problem to complete the task.

To see my progress visually, visit my website:

Scroll down to the billboard section with the email address, then hover over the black twitter icon to the upper left.

I want the fade-in action to occur only over the twitter Icon area, not the surrounding areas covered by the image. If you toggle the overflow of the wrapper, you'll notice a square area with a yellow border that fades in on hovering over the twitter icon. I want only this square area to activate the hover function, excluding other invisible overflowing content around it.

A non-Javascript solution would be preferred due to coding restrictions, but I am open to trying JS if necessary.

Thanks,

Isk

Answer №1

The issue you are experiencing stems from the fact that your image is nested within the wrapper div, causing hovering over the image to be interpreted as hovering over the wrapper div itself. If you are open to a solution involving Javascript, here's a suggestion: Move the larger image outside of the smaller wrapper div so they are no longer parent-child elements. However, position both elements in the same location as before. Then, trigger an onmouseover event on the smaller div to make the bigger image visible. Onmouseout, hide the bigger image again. To achieve this interaction between elements, you will need Javascript as CSS alone cannot accomplish it.

Below is the HTML and JS code that can be added to your HTML file:

<script>
function show(divId) {
  document.getElementById(divId).style.visibility = "visible";
}
function hide(divId) {
  document.getElementById(divId).style.visibility = "hidden";
}
</script>

<div id="small-button" onmouseover="show('bigger-image')" onmouseout="hide('bigger-image')">...</div>
<div id="bigger-image" style="visibility: hidden">...</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

How should a frame be correctly inserted into a modal in Bootstrap?

I'm currently working on incorporating a frame into a CSS modal, but the current display is not quite ideal. Additionally, I manually adjusted the frame's position (top and left), which is causing misalignment issues for different screen sizes, r ...

Show a picture on top of another picture

Is there a way to overlay an image and text on top of another image, similar to what is done on this website ? ...

Utilizing mat dialog in conjunction with the bootstrap sticky top class to enhance functionality

I am encountering an issue where, upon clicking to delete an entry, a mat dialog should appear with everything else in the background greyed out. However, the problem I am facing is that when I attempt to delete an entry, the dialog appears but the sticky ...

The void on the right side of the Safari browser

I am seeking assistance as I have encountered a problem on my website built using bootstrap 4.1. You can find my website at . The site functions correctly in chrome, firefox, opera, and IE, but when viewed on Safari, there is an unexpected white space on t ...

Libraries using the bootstrap slider are revolutionizing the design of all other layouts

Currently, I am utilizing a slider sourced from the following location: https://codepen.io/kravisingh/pen/pLGzgo Here is the complete code for the page: paste.ofcode.org/Dx5NyPRunupjL6GRysUx9g However, upon adding these libraries, the layout of other s ...

Connect two radio buttons across separate forms

I am encountering an issue with two radio buttons that I am trying to link together. The problem arises because they are located in two separate form elements, causing them not to function as intended. It is important for the forms to be utilized in Bootst ...

Switching the font style for the placeholder text

Can an input field have a different font-family for its text compared to its placeholder? I attempted to change the font-family of an input's placeholder using a pre-defined @font-face in CSS, but it didn't work: CSS .mainLoginInput::-webki ...

Develop dynamic div elements that have the ability to decompose on their own

I have a custom function called gainGold() which adds a new div element to a parent container in the following way: function gainGold() { $('#main').append('<div class="popup popup-gold">+ 14</div>'); } In the actual i ...

What is the technique for implementing a slide animation on hover to move a div identified by the class `box`?

How can I create a div element with the class of box that already has some transitions applied to it, and also include a slide animation on hover effect for the same div? .box { background-color: red; width: 70px; height: 70px; transition-propert ...

Carousel in Bootstrap Inline Styling

I need help aligning a Bootstrap 4 carousel next to another inline-block element (represented by an <img> element here). Every time I try to place them side by side, the carousel element shifts upwards by 50% of its height. How can I achieve perfect ...

Is it possible to eliminate the sticky class as you scroll down?

Check out this jQuery code I wrote to remove the sticky class while scrolling down: $(window).scroll(function (e) { if ($('.main_form_wrapper').length != 0) { var window_scroll = $(window).scrollTop(); console.log(window_scro ...

Connecting two divs with lines in Angular can be achieved by using SVG elements such as

* Tournament Brackets Tree Web Page In the process of developing a responsive tournament brackets tree web page. * Connection Challenge I am facing an issue where I need to connect each bracket, represented by individual divs, with decorative lines linki ...

Can we modify the cell width in knitr and pandoc?

When generating an HTML file using knitr/pandoc to display multiple tables in a loop, how can you ensure that each table has the same total width despite having varying numbers of cells? --- output: html_document: theme: cosmo --- {r results ="asis", e ...

Enhancing Child Elements with CSS - Evaluating Rating Systems

Is there a way to change the opacity of certain images inside my div when hovering over them? Specifically, I want the 4th image and the first three to have an opacity value of 1. I've looked into using nth-child but am unsure how to implement it for ...

What is the best way to set a jpg image as the background for an HTML div utilizing CSS/Bootstrap?

Struggling to set the background image for the first div in my home_no_user.html (which has an id of "background-image") to use the image yoga-stock.jpg. I've done this before without any issues, but for some reason, it's not working now, and I c ...

Having problems implementing FadeIn/Out effect while transitioning images on list item hover

I have managed to create a menu where the photo changes when hovering over a menu list item. However, I am struggling to add a fade in/out effect for a smooth transition between the photos. Here is the code: <div id="menu"> <img src ...

How to change the image source using jQuery when hovering over a div and set its class to active?

I am working with a div structure that looks like this: <div class="row margin-bottom-20"> <div class="col-md-3 service-box-v1" id="div1"> <div><a href="#"><img src="path" id="img1" /></a></div> ...

Designing an interactive region using HTML, CSS, and JavaScript

I recently created this code with some assistance: When I tried to format the code, it all ended up on one line and looked unreadable. To view the code properly, please visit this link: http://jsfiddle.net/QFF4x/ <div style="border:1px solid black;" ...

Applying position: absolute in HTML/CSS to lock parent and child elements in

Transform the boxes into concentric circles (circles within each other that share the same center). The outer circle should be black with a size of 300px and the inner circle should be white with a size of 200px. html: <div id="p10"> <div id ...

What is the reason for the difference in width between Bootstrap-5 row and regular div blocks?

My code may seem simple, but I have encountered an issue with it: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7abb7a9">[email protected]</a ...