Ali Bahaari Ali Bahaari - 4 months ago 11
CSS Question

How Bootstrap makes just Modal to scroll & not others?

I'm creating a modal like Bootstrap & everything is OK. The only thing I noticed is that Bootstrap prevent overflowing of BODY Tag when modal opens But modal has this property to overflow if the content in modal is more than the height of screen ..., How did that ? I added overflow: hidden; to body when modal opens & overflow: auto; to modal, But It doesn't work ...

Answer

Basically, once you take a HTML element out of the normal flow of elements, it's father element shouldn't effect the element itself.

So, the body has a overflow: hidden;, but since the overlay is positioned outside of the flow, the overflow doesn't effect it.

Since .overlay have overflow-y: auto, a scroll should appear specifically for the content of this element.

So, once an element is positioned with position: absolute or position: fixed, it shouldn't be effected by it's predecessor overflow

body {
    overflow: hidden;
}

.overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    padding: 30px;
    background: rgba(0, 0, 0, 0.5);
}

.modal {
    margin: auto;
    width: 400px;
    height: 1000px;
    background: white;
    border-radius: 5px;
    padding: 10px;
}
<div class="overlay">
    <div class="modal">I'm a long modal</div>
</div>


Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll. Everything here should not scroll.

Here's an external demo