Show an image when hovering over a dot using CSS - without hovering directly on the image

I'm currently working on a merchandising page that involves photoshopping several products onto a background image. I want customers to be able to hover over a dot positioned on each product to reveal its information and provide a link similar to . However, I am looking to achieve this using only CSS. My goal is for the info and link to appear when a user hovers on the dot and then on the containing div. The challenge I face is that both elements are contained within the same div, leading to messy displays with multiple products on the page. As a beginner coder, any assistance would be greatly appreciated. Thank you!

Here's the fiddle: http://jsfiddle.net/jakvisualdesign/hvb77m8L/2/

And here is the code:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<link rel="stylesheet" href="style.css">
<title>JS Bin</title>
</head>
<body>
<div id="container">

<div class="base">
    <img src="https://s3.amazonaws.com/steinersports/CMS+Pages/Yankees+Man+Cave/background.jpg" />
</div>
<div class="pop-container-a">
    <img src="https://s3.amazonaws.com/steinersports/CMS+Pages/Yankees+Man+Cave/background.jpg">
    <div class="dot"></div>
</div>
</div>
</body>
</html>

Now let's take a look at the CSS: #container { position:relative; width: 960px; margin-left: auto; margin-right: auto; }

.base {
width: 100%;
height: 100%;
position: absolute;
}

#container.pop-container-a img { 
position: absolute;
}

.dot {
width: 10px;
height: 10px;
position: absolute;
background-color: red;
z-index: 10;
border-radius: 50%;
}

.pop-container-a img { 
position:absolute;
opacity: 0;
width: 150px;
transition: opacity .5s ease;
}

.pop-container-a:hover .dot, .pop-container-a:hover img { 
opacity: 1;
}

.pop-container-a {
position: absolute;
top: 100px;
left: 50px;
display: inline-block;
}

Answer №1

Here's the solution for you: http://jsfiddle.net/hvb77m8L/3/

To achieve the desired effect, we used the adjacent sibling selector here with the hover on the dot affecting the image next to it. So, instead of:

.pop-container-a:hover .dot, .pop-container-a:hover img { 
    opacity: 1;
}

We changed it to:

.dot:hover + img { 
    opacity: 1;
}

Note: The Hover effect is now applied to an element immediately following the targeted one. Additionally, the HTML structure was adjusted from:

    <img src="https://s3.amazonaws.com/steinersports/CMS+Pages/Yankees+Man+Cave/background.jpg">
    <div class="dot"></div>

To:

    <div class="dot"></div>
    <img src="https://s3.amazonaws.com/steinersports/CMS+Pages/Yankees+Man+Cave/background.jpg">

Another note: To make the images remain visible when hovered on, their default width can be set to 0:

.pop-container-a img {
    opacity: 0;
    width: 0; // besides being invisible, the image won't respond to hovering
    position: absolute;
    transition: opacity .5s ease;
}

Then, when the dot is hovered, the images return to normal size and opacity:

.dot:hover + img {
    width: 150px;
    opacity: 1;
}

Lastly, once the image is in this state, it can maintain that appearance with a hover effect:

.dot + img:hover {
    width: 150px;
    opacity: 1;
}

A new fiddle showcasing this technique: http://jsfiddle.net/hvb77m8L/6/

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

Problem: Tailwind CSS styles are not being applied on responsive screens in Next.js.Issue: Despite

I'm attempting to apply a custom class to a div that should only be active on "md" screens. However, it doesn't seem to be working - <div className="md:myclass"/> tailwind-config.ts theme: { screens:{ 'sm': { ...

Having trouble aligning material-ui GridList in the center

I am currently working with a GridList in order to display Cards. The styling for these components is set up as shown below: card.js const useStyles = makeStyles({ card: { maxWidth: 240, margin: 10 }, media: { heigh ...

Error with Bootstrap 4 tabs and JavaScript AJAX implementation

I have implemented Bootstrap 4 tabs to showcase content fetched through an AJAX call. However, I encountered an issue upon completion of the call. The error message displayed is: Uncaught TypeError: $(...).tab is not a function The tabs are initially hi ...

Can you suggest a solution for fixing this error in Angular Js?

I recently started learning Angular JS and encountered some issues while trying to implement routing. Click here for the error message <!DOCTYPE html> Main <a href="#!london">City 1</a> <a href="#!paris">City 2& ...

Is there a way to target a button within an anchor tag without relying on a specific id attribute?

On my webpage, I have buttons that are generated dynamically using PHP from a MySQL table. Each button is wrapped in an anchor tag and when clicked, it triggers a Javascript function to carry out multiple tasks. One of these tasks requires extracting the ...

Reduce the size of text using HTML and CSS

I'm currently working on replicating an image using HTML and CSS that will be placed beneath the avatar on a forum. Here is what I have managed to achieve so far: https://jsfiddle.net/J7VBV/220/ table.avatarStats { border-spacing: 0; border- ...

Exploring the World of GiantBomb APIs

I have successfully created an account and obtained my API key. I am looking to implement a basic search functionality on my webpage, where users can enter a search query and click a button to display the game title and image. You can find more informatio ...

I am having trouble getting my dropdown to line up with the drop button labeled "MORE"

Despite trying multiple approaches, I am still struggling to align the dropdown content with the dropbtn. My goal is to have the content consistently positioned below the more menu. HTML: ` <html> <meta name="viewport" content="width=device-widt ...

I'm facing an issue where I am unable to connect images to specific pages within my carousel using Bootstrap on

Trying to link images in a carousel to pages on my website but encountering issues. Followed advice from other answers (Href in Bootstrap Carousel). Added the necessary href and included the correct .js from the Bootstrap site. The link is on the same host ...

ng-class not functioning properly when invoked

In my controller, I have the following function: $scope.menus = {}; $http.get('web/core/components/home/nav.json').success(function (data) { $scope.menus = data; $scope.validaMenu(); }).error(function () { console.log('ERRO') }); ...

Identifying flex-wrap capabilities across different browsers

Currently, I am developing a project that involves implementing a responsive grid using the flex wrap property. However, since my project needs to support IE9 and older versions of Firefox (version 28 and below), I am in need of a way to determine their ...

What is the best way to transfer data from a div tag to an li tag using JavaScript?

https://i.stack.imgur.com/se2qk.pngI am attempting to change the div tag content to li tag. Here is a snippet of the code from inspect for reference. I need to remove the div tag with the "domTitle" class. <li style="display: inline;" id="list_name"> ...

Why are my Bootstrap nav-tabs not showing tab-content in MVC?

I'm dynamically creating tab navigation from controllers using a list. <div class=""row> <div class="col-xl-3"> <!-- Tabs nav --> <div class="nav flex-column nav-pills nav-pills-custom" id="v-p ...

spaces between sections with no padding or borders

I came across the following layout on the web and noticed that the divs do not align perfectly. The top of a lower div does not touch the bottom of the div above it when borders are removed, although they do when borders are added. There seems to be an i ...

What is the best way to extract value from an input text that is being repeated using ng-repeat within a Tr

Having a table with repeated rows in angular, you can also dynamically add new rows by clicking a button. If there are already 3 repeated rows and 2 extra rows are added with data entered, how can we retrieve all the data from the table in the controller ...

Saving HTML data into the WordPress database with the help of Ajax

After developing a WordPress plugin, I encountered an issue while working with div elements. My goal is to retrieve the content of a specific div using the following code snippet: var archive = j( "div.page2" ).html(); console.log(archive); Everything wo ...

Which option offers superior performance: using attributes through HTML or jQuery?

At times, I find myself needing to include special classes, divs, and attributes in my HTML code for jQuery scripts to function properly (the site's "no-JavaScript" version doesn't require these elements). You probably understand what I mean. I& ...

Seeking assistance with creating an iPad application utilizing JQtouch - any t

I am attempting to create an iPad app using jQuery and jQTouch for the second time. I want to split the existing jQTouch theme designed for iPhone, which uses one window, into two separate windows optimized for the iPad. My goal is to have navigation on t ...

Putting text on top of an image using Bootstrap

Recently diving into the world of Bootstrap, I have come across a puzzling issue: Take a look at the HTML code from my website: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width ...

Avoid having Masonry load all divs simultaneously

I have experience using jQuery Masonry on Tumblr, but now I want to incorporate it into my portfolio website for displaying my photography. However, I'm struggling to find a solution that allows sets of images to load in as the user scrolls to the bot ...