The idea is to show the text in the span element as tooltip when hovered over the image using only CSS. The tooltip should appear above the image and to be centered relative to each image. There could be any number of images inside the div.
NOTE: I cannot change the structure of the HTML.
.parent-div {
position: relative;
}
img {
display: inline-block;
position: inherit;
}
img+span {
visibility: invisible;
width: 120px;
background-color: white;
color: black;
text-align: center;
border-radius: 6px;
padding: 5px 5px;
width: 120px;
top: -80%;
left: 9%;
margin-left: -16%;
position: absolute;
}
img+span:hover {
visibility: visible;
}
<div class="parent-div">
<img src="../icon.svg" alt="">
<span>Text1</span>
<img src="../icon2.svg" alt="">
<span>Text2</span>
</div>
But each span element position itself relative to the main div element, meaning that they appear above of the first icon and on top of one another.
I want the span element to be positioned relative to each img element.