I have a modal dialog in my app which can get quite long in the y direction. This introduces a problem whereby some of the content of the dialog is hidden off the bottom of the page.
I would like the window scrollbar to scroll the dialog when it is displayed and too long to fit on the screen but leave the main body in place behind the modal. If you use Trello then you know what I'm going for.
Is this possible without using JavaScript to control the scrollbar?
Here is the CSS I have applied to my modal and dialog so far:
body.blocked {
overflow: hidden;
}
.modal-screen {
background: #717174;
position: fixed;
overflow: hidden;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0.9;
z-index: 50;
}
.dialog {
background: #fff;
position: fixed;
padding: 12px;
top: 20%;
left: 50%;
z-index: 10000;
border-radius: 5px;
box-shadow: 0, 0, 8px, #111;
}
Window Page Scrollbar clickable when Modal is open
This one works for me. Pure CSS.
Try it and let me know
just use
it will arrange your modal and then give it an vertical scroll
position:fixed
implies that, well, the modal window will remain fixed relative to the viewpoint. I agree with your assessment that it's appropriate in this scenario, with that in mind why don'y you add a scrollbar to the modal window itself?If so, correct
max-height
andoverflow
properties should do the trick.Here is my demo of modal window that auto-resize to its content and starts scrolling when it does not fit the window.
Modal window demo (see comments in the HTML source code)
All done only with HTML and CSS - no JS required to display and resize the modal window
(but you still need it to display the window of course- in new version you don't need JS at all).Update (more demos):
Modal window aligned to top
Centered Modal window
Old demo that use Javascript
The point is to have outer and inner DIVs where the outer one defines the fixed position and the inner creates the scrolling. (In the demo there are actually more DIVs to make them look like an actual modal window.)
I wanted to add my pure CSS answer to this problem of modals with dynamic width and height. The following code also works with the following requirements:
HTML:
CSS/LESS:
This way the modal is always within the viewport. The width and height of the modal are as flexible as you like. I removed my close icon from this for simplicity.
simple way you can do this by adding this css So, you just added this to CSS:
and it's working!