0

In my code there could be hundreds of elements depending on how much images is added to the pages, meaning the height of the page could be between 0 to 1000s or even more.

How would I center a overlay div in the middle of the page. The webpage is more or less trying to mimic Instagram, you can have hundreds of images but once you click on one of them the overlay is still set in the middle of the page.

This is the main div for the overlay of the images. this div works fine as long as the page is no longer than the view height of the page, if the height is too large that you have to scroll down, then it will mess with the position of the vertical. I know this problem is because im setting the bottom to 15% so it takes in consideration the entire height value. But I dont know how I can fix that.

.overlayImgContainer{
        position: absolute;
        height: 70%;
        width: 120%;// (page is set to 960px this add a bit more room)
        z-index: 1;
        bottom: 15%;
        left: -10%;
        background-color: rgba(0,0,0,0.5);
        overflow-x: hidden;
        border-radius: 5px;
        text-align: center;
}

1 Answers1

-1

You can use flexboxes for that.

CSS

.wrapper {
   display: flex;
   align-items: center;
   justify-content: center;
}

HTML

<div class="wrapper">
   <div>...</div>
</div>
sam-s3pi0l
  • 73
  • 1
  • 5