I need to create an overlay element with HTML/CSS that covers only a certain container, not the whole page. I could use position:absolute;
and then everywhere 0px, but the trouble is that I cannot position the container that should be covered, it has to stay positioned static, and then position:absolute;
will not relate to this container.
So I tried to fix this setting height and width to 100%:
body {
background-color: grey;
}
#ovl {
height: 100%;
width: 100%;
background-color: #a10000a1;
}
#container {
border: 4px dotted blue;
}
<!DOCTYPE html>
<html>
<body>
<div id="container">
<div id="ovl">
This Overlay should hide the images.
</div>
<img height=300 src="1.png" class="imgs" alt="Error!">
<img height=300 src="2.png" class="imgs" alt="Error!">
<img height=300 src="3.png" class="imgs" alt="Error!">
</div>
</body>
</html>
I expected that the red overlay element would cover the whole container and the three images in it, but I got this. The three images (music scores) are not covered by the red overlay. Is there any error in my code? How to fix?