jqueryhtmlcssvertical-alignmenthtml5-fullscreen

Vertical centred fullscreen div with scroll bar


I would like to make fullscreen, vertical centred div overlaying all content below.

/* css */
#box {
    background: #fff;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

/* It is <body> tag class */
.overlay-hidden {
    overflow: hidden;
}

<!-- html -->
<body class="overlay-hidden">
    <div id="box">
        <!-- #box popup content goes here -->
    </div>
    <div class="container">
        <!-- content goes here -->
    </div>
</body>

Here is my code: https://jsfiddle.net/uzy78s69/ It seems work great but when I add more content to #box it does not work well https://jsfiddle.net/uzy78s69/1/

Click X or Create new post to check behaviour.

What I do wrong? How can I fix it?


Solution

  • Just add

    #box > .container {
      max-height: 100%;
    }
    

    JSfiddle: jsfiddle.net/uzy78s69/3