style.css:
.onhover
{
position:absolute;
}
.onhover .image
{
position:absolute;
}
.onhover .textonhover
{
font-size:30px;
visibility:hidden;
position:absolute;
display:flex;
justify-content:center;
align-items:center;
width:szerokość obrazka;
height:wysokość obrazka;
background-color:#ff0000;
opacity:0.6;
}
.onhover:hover .textonhover
{
visibility:visible;
}
kod HTML:
<!DOCTYPE HTML>
<html lang ="pl">
<head>
<meta charset = "utf-8"/>
<link rel = "stylesheet" href = "style.css"/>
</head>
<body>
<div class = "onhover">
<img src = "test.png" class = "image"/>
<span class = "textonhover">TEST</span>
</div>
</body>
</html>
Po najechaniu na obrazek pojawi się tekst na półprzezroczystym czerwonym tle