CSS hover effect with multiple image overlays on one area upon mouseover

I've been working on a map project that involves changing the color of multiple areas upon hovering using CSS. I've set up the main div with position:relative, and positioned the images inside absolutely to create hover effects by transitioning opacity from 0 to 1.

However, I'm facing an issue where I can't figure out how to apply the same CSS styling to multiple linked elements (the islands) for hover effects. When trying to mouse over one of these linked elements, the desired hover effect doesn't work as expected.

If anyone could provide assistance in resolving this issue, it would be greatly appreciated.

HTML

<div class="container">
<div id="main"> 
<img class="africa" src="./img/map/africa.png" height="50"/>
<img class="centralamerica" src="./img/map/centralamerica.png" height="50"/>
<img class="southamerica" src="./img/map/southamerica.png" height="50"/>
<img class="asiapacific" src="./img/map/asiapacific.png" height="50"/>

<a id="islandlink" href="#islandlink">
<img class="caribean" src="./img/map/caribean.png" height="50"/>
<img class="madagascar" src="./img/map/madagascar.png" height="50"/>
<img class="pacific" src="./img/map/pacific.png" height="50"/></a>

    </div>
</div>

CSS

.container {
  background-image: url(../img/map/map.png);
}

#main{
background-image: url(../img/map/map.png);
background-size: 960px 560px;
background-repeat: no-repeat;
width:960px;
height:560px;
position:relative;
}

#main img.africa {
top: 248px;
left: 405.59px;
height: 35.5%;
position: absolute;
width: 18%;
opacity:0;
}

#main img.southamerica {
top: 316px;
left: 240px;
height: 35%;
position: absolute;
width: 13.5%;
opacity:0;
}

#main img.centralamerica {
top: 256px;
left: 158px;
height: 12.7%;
position: absolute;
width: 10.8%;
opacity:0;
}

#main img.asiapacific {
top: 188px;
left: 584.5px;
height: 49%;
position: absolute;
opacity:0;
}

#main img.africa:hover {
top: 248px;
left: 405.59px;
height: 35.5%;
position: absolute;
width: 18%;
opacity:1;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
}

#main img.southamerica:hover {
top: 316px;
left: 240px;
height: 35%;
position: absolute;
width: 13.5%;
opacity:1;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
}

#main img.centralamerica:hover {
top: 256px;
left: 158px;
height: 12.7%;
position: absolute;
width: 10.8%;
opacity:1;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
}

#main img.asiapacific:hover {
top: 188px;
left: 584.5px;
height: 49%;
position: absolute;
opacity:1;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;
}

<!--Islands-->

#islandlink {
top: 316px;
left: 240px;
height: 35%;
position: relative;
width: 13.5%;
opacity:1;
}

#islandlink img.caribean {
top: 288px;
left: 251px;
height: 3.3%;
position: absolute;
opacity:0;
}

#islandlink img.madagascar {
top: 376px;
left: 548px;
height: 6.5%;
position: absolute;
opacity:0;
}

#islandlink img.pacific {
top: 346px;
left: 816px;
height: 5%;
position: absolute;
opacity:0;
}

#islandlink img:hover {
opacity:1;
transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-webkit-transition: opacity .5s ease-in-out;

}
}

Answer №1

If you're aiming to have all the island images show up simultaneously, consider adjusting your CSS with the following code:

#islandlink:hover img {
    transition: opacity .5s ease-in-out;
    -moz-transition: opacity .5s ease-in-out;
    -webkit-transition: opacity .5s ease-in-out;
    opacity:1;
}

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

There seems to be an issue with the item display page when clicking on the 'view details' button within the Bootstrap tab

Encountering a problem with displaying the product details page. There are four bootstrap tabs, each containing some Product Items with a Quick View link button. The issue arises when clicking on the link button, as all tab items with the same ID are displ ...

Unable to submit multiple forms simultaneously on the same HTML page

I have been encountering an issue with forms in a particular file. The problem arises when I click submit, rather than submitting the data from the filled form, it submits the data from the first form. Despite specifying unique ids for each form as shown i ...

Creating an interactive map on an image using HTML and drawing circles

I've been experimenting with drawing circles on images using the map property in HTML. I have an image set up, and when clicking on the image in JavaScript, I'm adding the area coordinates for the map property. However, I keep encountering a null ...

Troubleshooting problem with aligning grid items at the center in React using

I've been facing a challenge in centering my elements group using the material ui grid system. Problem: There seems to be excess margin space on the extreme right. Code snippet: const renderProjects = projects.map(project => ( <Grid item ...

What is the ideal location to store images that are referenced in a Django CSS file?

I recently downloaded a template from the internet which came with a base HTML file, images, and a CSS file. Now, I am attempting to incorporate all of this into my Django project. Unfortunately, my efforts have not been successful so far. The webpage is ...

Permission for resizing images after they are uploaded to the platform

Currently, I am working on a user's profile page where the user can upload their profile picture using a file dialog. However, when the file is moved to my local server's folder, it only receives permissions as 0644. I am looking to resize this ...

The element in the data cell is a form input field

This is the content of my webpage: <input type="text" class="form-control" >id="ButonSociete"name="ButonSociete"placeholder="Societe"> <table cellpadding="0" cellspacing="0" border="0" class="display" >id="demande" width="100%"> ...

How to align an image in the middle using Bootstrap and React

Having an issue with Bootstrap and aligning an image in the center. Currently, the image is appearing left-aligned: Here is the HTML: <div className="App vh-100"> <div className="d-flex h-70 border border-white container"> <div class ...

Is it possible to transform all scripts into a React component? (LuckyOrange)

I am currently working on converting the script for a specific service (http://luckyorange.com/) into a component. The instructions say to place it in index.html within the public folder, but that appears to be insecure. I'm uncertain whether this tas ...

Issue with consistent search autocomplete feature in a stationary navigation bar using bootstrap technology

My issue is with the autocomplete box - I want it to have the same width as the entire search box. Something like this using Bootstrap's col-xs-11 class: https://i.sstatic.net/npzhC.png If I set the position to "relative," it looks like this (all st ...

Tips for managing three select menus in AngularJS

Assistance needed for creating a series of interconnected dropdown menus in AngularJS. The functionality should allow the second dropdown to open upon selecting a value in the first dropdown, and the third dropdown to open upon selecting a value in the sec ...

CSS: using syntax to target element by its unique identifier

Check out this guide: I followed the instructions and used an external stylesheet. I added #menu before each CSS item, for example: #menu ul{ font-family: Arial, Verdana; font-size: 14px; margin: 0; padding: 0; list-style: none;} or: #menu ul li{ displ ...

Tips for adjusting the height of a selection box in jQuery Mobile

I am trying to make the select box height the same as the label (模板分類:). <select id="TamplateClass" style="height:1.5em">...</select> you can use CSS #TamplateClass{height:1.5em;} However, no matter what I try, the results are all th ...

What is the most efficient method for clearing the innerHTML when dealing with dynamic content?

Is there a more efficient method for cleaning the innerHTML of an element that is constantly changing? I created a function to clean the containers, but I'm not sure if it's the most efficient approach. While it works with the specified containe ...

Angular - Variables not visible to controller in HTML

Seeking assistance to connect my controller with my HTML variables and functions. Any help is appreciated! HTML: <article ng-controller="CreateUserController"> <div class="well"> <center> <h1>Registrar</h1> <b ...

Nightwatch failing to locate element within iFrame

I'm currently facing a challenge when trying to access an element within an iframe. Despite successfully switching to the frame, Nightwatch keeps returning "element not found" whenever I attempt to verify its presence or visibility. Below is a snippe ...

How to dynamically insert elements into the HTML page using Angular

When my page first loads, it looks like this <body> <div class="col-md-12" id="dataPanes"> <div class="row dataPane"> Chunk of html elements </div> </div> <div class"col-md-12 text-right"> <input type="butt ...

Stretching the limits: Combining and expanding your Styled Components theme

I am facing a situation where I have a component library built using Styled Components that has its own theme settings which are not meant to be overridden. Now, I need to incorporate this component library into another project that also uses Style Compone ...

The "getJson" function fails to execute when attempting to run a Python

I've come across a simple code snippet, but for some reason, my getjson function isn't working as expected. My Python script properly prints a JSON encoded value. Does anyone have any suggestions? HTML <!DOCTYPE html> <html> <h ...

Is there a way to modify the CSS or add custom styling within an iframe form?

Currently I am working on the following page: , where an embedded javascript form called infusionsoft (iframe form) needs to be made responsive at the request of my client. I'm wondering if there is a way to override the css or inject custom styles i ...