Reputation: 1063
What i have:
A Block element with fixed size, but dynamic content size and overflow: scroll;
.
What i want:
A transparent layer over the content, so no matter how far the parent is scrolled the layer covers the content.
What i tried:
.layer {
position: relative;
width: 100%;
height: 100%;
bottom: 100%;
z-index: 20;
}
inside the parent after the content.
The issue:
The layer covers the parent properly, but as soon as i scroll it doesn't cover the content.
Fiddle:
Red should cover everything, but not too much;
Upvotes: 4
Views: 3462
Reputation: 4141
Height: 100%;
give the element the same height as it's parent.
The parent you have defined is not as high as the content you want to cover.
If you put the "layer" inside your "content" in your markup, you can then absolute position it relative to the "content". So now the height: 100%
will relate to the content instead of the "parent" (scroll window).
Also, when you want to position something absolute, that element will relate to it's closest non-static parent.
Here is the fiddle.
Upvotes: 3
Reputation: 1915
Try this:
HTML:
<div class="coverable">
<div class="layer"></div>
Content that gets covered!
</div>
CSS:
.coverable {
position: relative;
}
.coverable .layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
bottom: 100%;
z-index: 20;
}
Upvotes: 2