Ok so I have read numerous SO questions and answers about this one, looked at various JSFiddle and Codepen examples but don't seem to find the solution I want...
Here is an example fiddle of what I'm experiencing:
https://jsfiddle.net/ts4t13hn/3/
Here is the CSS class I'm working with:
.dark-layer{
background-color: rgba(0,0,0,.6);
height:100%;
width:100%;
}
Basically, I want the CSS class 'dark-layer' to fill 100% of the screen (whether the content fits onto the page or there is more and one has to scroll down to see the rest).
In the fiddle example above, there isn't enough content to require the user to scroll down so the layer doesn't cover 100% of the screen. The solution to this I found was to give the class position:absolute
- working example here: https://jsfiddle.net/ts4t13hn/4/
However, if I now add some more content to cause an overflow, the layer doesn't continue to fill the screen as demonstrated here: https://jsfiddle.net/ts4t13hn/5/
Various pieces of information suggest setting background-attachment:fixed
but I tried this in the fiddle and my project and I see no difference.
If I leave my CSS as in the first example (i.e. no position:absolute;
), I get the desired result only if the content exceeds the initial screen.
The question: Is there a way to give the dark-layer
class 100% height and cause it to be fixed to the viewport so that it is always covering the background image (similar to how to how the background image on the body element works)