CSS – full screen overlay layer
May 20, 2010 10 Comments
Often when you display a gallery of pictures, you want to dim the website in to the background. I have tryed implementing several solutions based on placing a html element on top of all the others by setting position to absolute, and height and width to 100%. That worked ok as long as the page was no bigger than the screen. But when i scrolled the page i noted that my absolute layer was attached to the top of the page,.. so it scrolled with the page,.. so that was clearly not the way to go,..
So here’s what i came up with to solve this,..
.dim { height:100%; width:100%; position:fixed; left:0; top:0; z-index:1 !important; background-color:black; }
and it worked as a charm,.. position fixed did the trick,. woohoo,..
to make this overlay more fancy you can add opacity to it by setting a
semitransparent png pixel to the background(works in most browsers)
or do it the old fashioned way
filter: alpha(opacity=75); /* internet explorer */ -khtml-opacity: 0.75; /* khtml, old safari */ -moz-opacity: 0.75; /* mozilla, netscape */ opacity: 0.75; /* fx, safari, opera */
This really helped me, thank you.
Thank you, works perfectly.
You are welcome. Nice to hear it helped someone (c:
Thank you maanehunden, it helped me a lot
Just what I needed, thank you!
nice to hear,.. keep on coding (c:
there is a slight bug in iphone safari. when you scroll down the page it drags up a bit of white space. when you let go your finger off the screen, the white space is then filled by the overlay again and it looks fine.
anybody have a solution?
update: its the safari top header address bar height that causes problems.
by putting bottom value to “bottom:-60px” it seems to fix it 🙂
You have no idea, how thankful i’m for this post.
I never thought, that position fixed, not absolute, would be perfect solution for my problem.
God bless you!
😀
Thanx ,.. Glad I could help