Achieving a div overlapping effect on hover

I was trying to set up a div that displays information about a product when the user hovers over it, but for some reason the info div keeps glitching and is not staying stable. Here's the code:

.product {
  position: absolute;
  background-color: blue;
  width: 100px;
  height: 200px;
  z-index: 1;
}
.info {
  position: absolute;
  background-color: red;
  width: 300px;
  height: 300px;
  z-index: 2;
  opacity: 0.5;
  visibility: hidden;
}
.product:hover + .info {
  visibility: visible;
}
<div class="parent">
  <div class="product"></div>
  <div class="info"></div>
</div>

How can I prevent the glitching and have a stable version of this feature without the info div constantly appearing and disappearing?

Answer №1

The reason for this issue is that your mouse is currently hovering over .info instead of .product. To solve this problem, you will need to include the selector .info:hover

.product {
  position: absolute;
  background-color: blue;
  width: 100px;
  height: 200px;
  z-index: 1;
}
.info {
  position: absolute;
  background-color: red;
  width: 300px;
  height: 300px;
  z-index: 2;
  opacity: 0.5;
  visibility: hidden;
}
.product:hover + .info, .info:hover {
  visibility: visible;
}
<div class="parent">
  <div class="product"></div>
  <div class="info"></div>
</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

Interference of setInterval with other setInterval functions

Attempting to set up multiple setInterval functions and store them (for later clearing) results in the last setInterval overriding the previous ones. This causes each interval to execute only once, with the same output. Below is a code snippet demonstrati ...

Why isn't anything happening with the .class element?

I've been diving into the world of CSS and stumbled upon something that's left me puzzled. Here is a snippet of HTML code: <ul class="weblist"> <li>Coffee Brur</li> <li>Taco Finder</li> <li>CSS Se ...

What is the best way to ensure a PrimeVue TabPanel takes up the full vertical space and allows the content within the tabs to be scroll

I have created a sandbox demo to illustrate my issue. My goal is to make the content of tabs scroll when necessary but fill to the bottom if not needed. I believe using flex columns could be the solution, however, my attempts so far have been unsuccessful. ...

Moving pictures using css3 transitions

Trying to create a straightforward image slider. Below is the provided JavaScript code: $(document).ready(function() { $('#slide1_images').on('click', 'img', function(){ $("#slide1_images").css("transform","translateX ...

Retrieving data from a Ruby class based on a specific condition

Currently, I have a code snippet that adjusts the formatting of an editing page based on the number of values a question contains. <% (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aa9b8484eadbdfcfec8cdcac3c5c484dbc6ece0 ...

Adding Tooltips to Your Bootstrap 5 Floating Labels Form: A Step-by-Step Guide

Can you include tooltips or popovers in Bootstrap 5 floating labels text? I've set up a form with floating form fields and I'd like to provide instructions for certain fields using tooltips or popovers. I can make it work with the standard form ...

How do I add a logo next to a title using CSS Bootstrap?

I am having trouble using Bootstrap to position my logo alongside my website name. I opted for Bootstrap because I want it to adapt smoothly as the webpage's dimensions change, but I'm struggling to get it right. Since I'm new to Bootstrap, ...

Ways to dynamically adjust the color of the text font?

Below is the XML content: span style="background-color: rgb(255, 255, 0); The background color mentioned here is linked to my Java code. Since this color changes dynamically, it varies in each report. My inquiry is about how to incorporate this color in ...

Adjusting Opentok React video to utilize the complete height of the encompassing container

I'm currently utilizing https://www.npmjs.com/package/opentok-react within my application and setting up a publisher and subscriber in a specific div. This is the CSS I have implemented: #videos { position: fixed; right: 0; bottom: 0; ...

Best practice for injecting dynamic HTML using .ajax() call

Here is an example of a successful JSON Facebook Graph API request that retrieves data objects and displays their page-id pictures inside `img` tags within the `#results` div. success: function(res){ console.log(res); ...

Spinning a CSS object around an axis

Trying to add a unique touch to my image rotation with CSS. While familiar with rotating around x, y, and z axis, I want to achieve a diagonal rotation this time. Wondering if there's a way to tweak the y axis for a more slanted effect on my image? ...

What is preventing the code from concealing the html div when the winOrNot function is given the argument (false)?

Can you identify why the "Congratulations" message in the div is not being hidden when the function is called with the (false) argument? <!DOCTYPE html> <html> <head> <title></title> </head> <body> <div id= ...

What might be causing my grid columns to move onto a new line?

I am facing an issue with my Bootstrap 4 buttons. I have set them up to be 4 columns each within a grid, expecting them to all remain on the same row. However, the third button is dropping down to the next line and I can't seem to figure out why. Her ...

Straightforward, rudimentary example of Typescript knockout

I am hoping to successfully implement a basic TypeScript Knockout example. I utilized Nugget to acquire the TypeScript Knockout and downloaded Knockout 3.0.o js. Below is my TypeScript file: declare var ko; class AppViewModel { firstName = ko.observa ...

Incorporating library files (css/js) into your app built on the angular-fullstack framework

After using a Yo Angular-Fullstack generator (https://github.com/DaftMonk/generator-angular-fullstack) to start an app, I attempted to install Toastr from bower with the command: bower install angular-toastr Now, I need to add the toastr css and js files ...

Passing data from the server to client-side scripts using $_POST

I am developing a basic drawing tool using JavaScript, and I have utilized PHP to generate a table that serves as the canvas. In order to allow for customization of dimensions, I implemented the following code: $input = $_SERVER['REQUEST_METHOD' ...

Eliminate the need for pressing the "tab" key on my website

I'm currently working on a horizontal web page layout and I'm looking for a way to disable the "tab" button functionality on my page. The issue arises because I have a contact form with textboxes located in the last div, and when users navigate u ...

Dynamically load values for AJAX functions

I am working on a dynamic list of strings that are generated through an AJAX call. Here is the function I am using: function updateIngredients(boxId, prodid) { $.ajax({ type: "GET", url: "/Products/FetchBoxIngredients?idbox ...

Is there a way to modify the color of ASCII art letters within HTML's <pre> tags?

For this illustration, I aim to transform the letter "y" into a shade of blue. ,ggggggggggggggg dP""""""88""""""" Yb,_ 88 `"" 88 88 88 gg gg 88 I8 8I gg, 88 ...

EnhanceTo ensures that every added element is distinct while making use of the identical jQuery

I'm curious if it's feasible to make each new div unique on each appendTo call but still utilize the same jQuery functionality. As shown in the markup below, every new div shares the same jQuery code and therefore doesn't work independently ...