Home > Enterprise >  set the height of the modal to be the same as the viewport
set the height of the modal to be the same as the viewport

Time:10-07

When I click on the image, the modal appears, I would like to make it the same height of the viewport and the same width of it, since as it looks like now I have to scroll down.

This is the css of the modal and the modal content:

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: black;
}

/* Modal Content */
.modal-content {
  position: relative;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  width: 90%;
  max-width: 1200px;
}

I've created a minimal example here

https://jsfiddle.net/rnyjdp87/1/

Also, I would like to put a button a button on the top right of each image that is gonna open a second modal if clicked (still have to do the second modal). Thank you!

CodePudding user response:

Not sure I understand but try this:

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  overflow: none;
  background-color: black;
}

/* Modal Content */
.modal-content {
  position: relative;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  width: 100%;
  max-width: 1200px;
}

.modal-content img {
  max-height: 80vh;
  width: auto;
  max-width: 100%;
}

This will set your modal to 100% viewport height, 100% viewport width and changing overflow to none stops the scroll.

  • Related