Check out this cool interactive map on CodePen.
I managed to create a solution for an interactive map without using any JavaScript. Even though the example with <dl>
and <dd>
elements seemed a bit unclear, I worked through it successfully. I believe that using more specific elements like <figure>
could make the process even smoother. Each element you hover over should have a distinct "hover" image to handle overlaps in the rectangles effectively.
HTML
<dl class="map">
<dd>
<figcaption>
<p>Man 1</p>
</figcaption>
</dd>
<dd>
<figcaption>
<p>Man 2</p>
</figcaption>
</dd>
<dd>
<figcaption>
<p>Man 3</p>
</figcaption>
</dd>
<dd>
<figcaption>
<p>Man 4</p>
</figcaption>
</dd>
<dd>
<figcaption>
<p>Man 5</p>
</figcaption>
</dd>
</dl>
CSS
.map {
display: block;
margin: 50px 0px 0px 40px;
padding: 0px;
position: relative;
background: url('map_silhouette_black.png');
width: 600px;
height: 400px;
}
.map dd {
display: block;
margin: 0px;
padding: 0px;
position: absolute;
cursor: pointer;
}
.map dd figcaption {
display: none;
margin: -50px 0px 0px -60px;
padding: 10px;
position: relative;
background: #333;
color: #FFF;
font: 14px sans-serif;
text-align: center;
border-radius: 100%;
width: 120px;
box-sizing: border-box;
}
.map dd figcaption:before {
content: '';
display: block;
position: absolute;
bottom: -15px;
left: 50%;
border: 10px #333 solid;
border-left-color: transparent;
border-bottom-color: transparent;
}
.map dd:hover figcaption {
display: block;
}
.map dd:nth-child(1) {
top: 20px;
left: 20px;
background-position: -20px -20px;
width: 115px;
height: 335px;
}
.map dd:nth-child(2) {
top: 20px;
left: 135px;
background-position: -135px -20px;
width: 115px;
height: 345px;
}
.map dd:nth-child(3) {
top: 5px;
left: 250px;
background-position: -250px -5px;
width: 125px;
height: 385px;
}
.map dd:nth-child(4) {
top: 25px;
left: 360px;
background-position: -360px -25px;
width: 120px;
height: 350px;
}
.map dd:nth-child(5) {
top: 25px;
left: 470px;
background-position: -470px -25px;
width: 110px;
height: 330px;
}
.map dd:nth-child(1):hover {
background-image: url('map_silhouette_color1.png');
}
.map dd:nth-child(2):hover {
background-image: url('map_silhouette_color2.png');
}
.map dd:nth-child(3):hover {
background-image: url('map_silhouette_color3.png');
}
.map dd:nth-child(4):hover {
background-image: url('map_silhouette_color4.png');
}
.map dd:nth-child(5):hover {
background-image: url('map_silhouette_color5.png');
}