Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable whole page with an overlay

Tags:

html

css

I want to create an overlay that I will use behind a popup. But when the page is scrolled down the overlay is no more there? I can use javascript to get the height of page's content and then can apply same height to overlay but is there any css based solution?

#overlay{
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0px;
   top: 0px;
   background-color:#000;
   opacity: .75
}
like image 838
user1444021 Avatar asked Jun 08 '12 08:06

user1444021


People also ask

How to prevent body scrolling but allow overlay scrolling?

Approach: To prevent body scrolling but allow overlay scrolling we have to switch the overflow to be hidden when the overlay is being shown. And while the whole page's overflow is hidden or the scroll is disabled the overflow in the y-axis of the overlay is enabled and the overflow can be scrolled.

How do I make an overlay for my page?

One of the ways of creating an overlay is by absolutely positioning an HTML element on the page. We create <div> element in the markup then position it absolutely with the position property. After it, we give the <div> high z-index value to make it on top of all other elements on the page with the z-index property.

How do you disable a page in HTML?

The basic technique for this is to add a 100% width and height div on top of everything. $('body'). append('<div class="cover"/>'). css({ position: 'absolute', height: '100%', width: '100%', zIndex: '999' });


2 Answers

position must be fixed and also to prevent stacking problems add z-index: 9999999;
demo on dabblet.com

#overlay{
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color:#000;
    opacity: .75;
    z-index: 9999999;
}
like image 52
Vladimir Starkov Avatar answered Nov 02 '22 23:11

Vladimir Starkov


just change the position attribute to fixed.

like image 34
Tooraj Jam Avatar answered Nov 03 '22 00:11

Tooraj Jam