I have a span that shows up when Im hovering over the img. I would like now to center it in the image. How do I do that?
Like here:Pic
Here is my code:
const container = document.querySelector('#container');
const description = document.querySelector('.description');
container.addEventListener('mouseenter', e => {
description.classList.remove('hidden');
});
container.addEventListener('mouseleave', e => {
description.classList.add('hidden');
});
#container {
position: relative;
width: 100%;
}
.description {
position: absolute;
}
.hidden {
display: none;
}
span {
color: #FFFFFF;
font-size: 80px;
}
img {
width: 50%;
}
<html lang="de">
<body>
<div id="container">
<span class="description hidden">--TEXT--</span>
<img id="image" src="https://i.pinimg.com/originals/1a/12/32/1a123232bfeaaec0a23eb0f83158e76a.jpg">
</div>
</body>
</html>