There are a myriad of ways to do this. I made a small example that can help you. Read the code and one studied in it to understand what was done and how you can customize it. I left the css as simple as possible to make it easier to understand.
I used transition
to make the appearance appear and a pseudo element to create the caption using a custom attribute data-name
in the content
of the pseudo element. Another thing the element <img>
does not needs the closing tag </img>
See the example to better understand:
a {
position: relative;
}
a::after {
content: attr(data-name);
position: absolute;
left: 0;
top: 100%;
width: 100%;
background-color: red;
text-align: center;
transform: scaleY(0);
transform-origin: top;
opacity: 0;
transition: opacity 300ms, transform 300ms;
}
a:hover::after {
transform: scaleY(1);
opacity: 1;
}
<a target="_blank" data-name="legenda" href="cadastro" ><img src="https://cssreference.io/images/css-reference-icon.png"style="margin:2px; width: 100px;"></a>
<a target="_blank" data-name="legenda" href="empresas.php"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQIBmLAlfom6jbOjZGV71PLUC_nlr__DfkDMI0Ny4vY4R3fKc_n"style="margin:2px;width:100px;"></a>