Overlaying one div over another, but not knowing the size of the div
Posted
by
andyuk
on Stack Overflow
See other posts from Stack Overflow
or by andyuk
Published on 2012-07-09T11:59:03Z
Indexed on
2014/05/30
9:28 UTC
Read the original article
Hit count: 181
I'm trying to lay one div over another. This is really simple if you know the dimensions of the div.
Solved here: How to overlay one div over another div
So, here is my HTML:
<div class="container">
<div class="overlay"></div>
<div class="content"></div>
</div>
In my case, I don't know the exact dimensions of the "content" or "container" div. This is because I don't have control over any of the content in the div (we are making our app extensible for 3rd party developers).
See my example on jsFiddle The overlay should cover the content entirely. Width 100% and Height 100%. However, this does not work because in my example I positioned the overlay absolutely.
One solution is to use JavaScript to get the size of the content div and then set the size of the overlay. I don't like this solution much since if image sizes are not specified, you need to wait until images are loaded and recalculate the size of the div.
Is there any way of solving this problem in CSS?
© Stack Overflow or respective owner