Adding multiple modals to a page

Yes…but depending on the page, I just need to print the modal and the page to print would not be important. If I had to choose one over the other, I would pick print modal content and not the page.

As mentioned before, that seems to be the advantage of using onclick="window.open with sized windows. But I am told by people on this forum in the past is that those are somewhat outdated. So I am trying to bring things as current as possible and there seems to be a compromise in doing that. And of course, using the modal is nicer looking. I would really like your opinion in this matter.

I would use the modal and add a Print button as in the demo I linked to :slight_smile:

1 Like

You could just add a class to the body when the modal is open in your demo above and then let css do the rest. No need for a specific print button as such.

e.g.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal demo</title>
<style>
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.modal-overlay {
	position: fixed;
	top:0;
	left:0;
	display: none;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, .5);
	opacity: 0;
	transition: opacity .2s ease;
}
.modal-overlay.active {
	display: table;
}
.modal-overlay.visible {
	opacity: 1;
}
.modal-inner {
	display: table-cell;
	vertical-align: middle;
}
.modal-container {
	margin: 0 auto;
	width: 50%;
	min-width: 750px;
	max-width: 850px;
	max-height: 600px;
	overflow: auto;
	border: 1px solid;
	background: #fff;
	border-radius: 5px;
}
.modal-header {
	text-align: right;
}
.modal-close {
	margin-right: .25em;
	color: inherit;
	text-decoration: none;
	font-size: 2rem;
	font-weight: bold;
}
.modal-content {
	padding: 0 10px;
}
.modal-content p {
	margin: 0 0 1em;
}
.hide {
	display: none;
}
p.open {
	margin: 1em;
	text-align: center;
	font-size: 1em;
	font-weight: 600;
	color: #4c659b;
	text-transform: uppercase;
	font-family: Arial, Helvetica, sans-serif;
}
@media print {
	body.modal-visible > *{visibility:hidden;}	
	body.modal-visible > .modal-overlay {visibility:visible;}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;}
	.modal-container{border:none;width:auto;min-width:0;max-width:none;max-height:none;}
	.modal-header{display:none;}
}


</style>
</head>
<body>
<a href="#" data-open-modal data-modal="1">Modal 1</a><br>
<a href="#" data-open-modal data-modal="2">Modal 2</a>
<div class="modal-overlay">
  <div class="modal-inner">
    <div class="modal-container">
      <div class="modal-header"> <a href="#" class="modal-close">&times;</a> </div>
      <div class="modal-content-1 hide"> Hello from modal 1 </div>
      <div class="modal-content-2 hide"> Hello from modal 2 </div>
    </div>
  </div>
</div>
<script>
      window.onload = function () {
        var openModalLinks = Array.prototype.slice.call(document.querySelectorAll('[data-open-modal]'));
        var closeModal = document.querySelector('.modal-close');
        var modalOverlay = document.querySelector('.modal-overlay');
        var modalInner = document.querySelector('.modal-inner');
        var modalContent = document.querySelector('.modal-inner');
        var modalContent = Array.prototype.slice.call(document.querySelectorAll('div[class^="modal-content-"]'));

        var handleShowModal = function (id) {
		  document.querySelector('body').classList.add('modal-visible');	
          modalOverlay.classList.add('visible');
          modalOverlay.querySelector('.modal-content-' + id).classList.remove('hide');
        }

        var handleHideModal = function (event) {
          modalOverlay.classList.remove('active');
        }

        var handleOpenModal = function (event) {
          var id = event.target.getAttribute('data-modal');

          event.preventDefault();
          modalOverlay.classList.add('active');

          window.setTimeout(handleShowModal(id));
        }

        var handleCloseModal = function (event) {
          if (event.target !== event.currentTarget) {
            return;
          }

          event.preventDefault();
		  document.querySelector('body').classList.remove('modal-visible')	
          modalOverlay.classList.remove('visible');
          modalContent.forEach(function(modal) { modal.classList.add('hide') });

          modalOverlay.addEventListener(
            'transitionend',
            handleHideModal, {
              once: true,
              passive: true
            }
          );
        }

        openModalLinks.forEach(function(link) {  link.addEventListener('click', handleOpenModal) });
        closeModal.addEventListener('click', handleCloseModal);
        modalInner.addEventListener('click', handleCloseModal);
      }
    </script>
</body>
</html>

Of course a print button may make it more obvious that modal contents only will be printed but I have to agree that if a modal is open and a user instigates a browser print then they were intending to see the modal content printed only and not the content behind.:slight_smile:

1 Like

Aw man, we are not worthy…

I’m going to examine this solution in some detail when I have a minute, as I was at a loss as to how to do this with pure CSS.

Nice one, Paul.

1 Like

You still need js to add the class to the body but apart from that css can do the rest. :slight_smile:

Some things to note though:

body.modal-visible > * {visibility:hidden;}
body.modal-visible > .modal-overlay {visibility:visible}

Because visibility can be over-ridden in child elements (unlike display:none) then in a real application you would probably want to lose the child selector as any child that is visibility:visible will be visible.

Also for print stylesheets !important is one of those cases where it can be safely used and not seen as a hack,

body.modal-visible  * {visibility:hidden!important;}
body.modal-visible  .modal-overlay,body.modal-visible .modal-overlay * {visibility:visible!important}

Hey Paul,

Just sat down to play with this (your code from #23) and on Firefox, when I open a modal and print, I see:

Where the bar continues all the way down the page.

Is this intended behavior?

I would have expected it to have only printed “Hello from modal 1” and no bar.

I’ve just checked in Chrome and Firefox and all they print is the text “Hello from modal 1” or Hello from Modal 2".

The text in your screenshot looks odd and much too large and not sure where the gray background has come from.

If you have other styles in your example you may want to do the normal print stylesheet things such as setting the body background to white and the text to black etc. Also the border radius could be removed from the modal styles also although in the code I posted it made no difference as there was no background.

@media print {
	html,body{background:#fff!important;color:#000!important;}
	body.modal-visible  * {visibility:hidden!important;}
	body.modal-visible  .modal-overlay, body.modal-visible .modal-overlay * {visibility:visible!important}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;height:auto;background:#fff;}
	.modal-container{border:none;width:auto;min-width:0;max-width:none;max-height:none;border-radius:0}
	.modal-header{display:none;}
}

To debug a print sheet just remove the media query from around those styles and then you can use devtools to see where your backgrounds are coming from.

Paul,

Thank you for chiming into this thread. Your input is invaluable!

When I incorporate your code and take away the no display code on the main page this is the results:
I have taken out no display on the underlying page.

  1. IE 11 shows the underlying information on the page when printing the modal.
  2. In FF and Chrome, works great, but it print the results twice. (2 pages of same data of modal content)

Thanks

Edit: PS. Edge responses same as IE11

Disregard my last post:

Thank you for chiming into this thread. Your input is invaluable!

When I incorporate your code and take away the no display code on the main page this is the results:
I have taken out no display on the underlying page.

1.IE 11, EDGE, FF and Chrome shows the underlying information on the page when printing the modal.
Thanks

Lol, Linux.

This did the trick for me:

.modal-overlay: { background: #fff }

Which I guess is necessary due to:

.modal-overlay {
  ...
  background-color: rgba(0, 0, 0, .5);
  ...
}

Examining the code in more depth, it is actually quite easy to understand.

body.modal-visible > *{visibility:hidden;}
body.modal-visible > .modal-overlay {visibility:visible;}

Here you are using the class added to the body when the modal is displayed to hide everything except for the modal overlay.

.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;background:#fff;}
.modal-container{border:none;width:auto;min-width:0;max-width:none;max-height:none;}
.modal-header{display:none;}

And here you are knocking out any additional styles (e.g. the background color, the positioning) to ensure that it displays as black text on a white background in the top left hand corner of the screen.

Did I get that right?

2 Likes

I don’t want to comment yet on James’ and Paul’s interactions because they are truly the ultimate pros at doing this. I will wait until the comments are pieced together in the code.

I would like to make this comment though because I forgot this earlier. In printing the modal content, only the part that is on the screen prints - it doesn’t print the entire modal if it’s in the scroll down part. Perhaps that is the way it’s suppose to be; I don’t know.

It sounds as though you haven’t negated the height and overflow settings in the prnt stylesheet.

For example if you have this in your main stylesheet.

.modal-container {
	margin: 0 auto;
	width: 50%;
	min-width: 750px;
	max-width: 850px;
	max-height: 600px;
	overflow: auto;
	border: 1px solid;
	background: #fff;
	border-radius: 5px;
}

Then in your print stylesheet you would want to over-ride those settings as they make no sense on a printed page.

e.g.

@media print{
	.modal-container {
		margin: 0 auto;
		width:auto;
		height:auto;
		min-width:0;
		max-width:none;
		max-height:none;
		overflow: visible;
		border:none;
		background: #fff;
		border-radius: 0;
	}
}

You have to make sure that what you are printing is in a suitable format for paper so things like width height and overflow must be controlled (along with colours and backgrounds of course).

This example works for me in all browsers mentioned:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal demo</title>
<style>
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.modal-overlay {
	position: fixed;
	top:0;
	left:0;
	display: none;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, .5);
	opacity: 0;
	transition: opacity .2s ease;
}
.modal-overlay.active {
	display: table;
}
.modal-overlay.visible {
	opacity: 1;
}
.modal-inner {
	display: table-cell;
	vertical-align: middle;
}
.modal-container {
	margin: 0 auto;
	width: 50%;
	min-width: 750px;
	max-width: 850px;
	max-height: 600px;
	overflow: auto;
	border: 1px solid;
	background: #fff;
	border-radius: 5px;
}
.modal-header {
	text-align: right;
}
.modal-close {
	margin-right: .25em;
	color: inherit;
	text-decoration: none;
	font-size: 2rem;
	font-weight: bold;
}
.modal-content {
	padding: 0 10px;
}
.modal-content p {
	margin: 0 0 1em;
}
.hide {
	display: none;
}
p.open {
	margin: 1em;
	text-align: center;
	font-size: 1em;
	font-weight: 600;
	color: #4c659b;
	text-transform: uppercase;
	font-family: Arial, Helvetica, sans-serif;
}
@media print {
	html,body{background:#fff!important;color:#000!important;}
	body.modal-visible  * {visibility:hidden!important;}
	body.modal-visible  .modal-overlay, body.modal-visible .modal-overlay * {visibility:visible!important}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;height:auto;background:#fff;}
	.modal-container{border:none;width:auto;height:auto;min-width:0;max-width:none;max-height:none;border-radius:0;overflow:visible}
	.modal-header{display:none;}
}



</style>
</head>
<body>
<a href="#" data-open-modal data-modal="1">Modal 1</a><br>
<a href="#" data-open-modal data-modal="2">Modal 2</a>
<div class="modal-overlay">
  <div class="modal-inner">
    <div class="modal-container">
      <div class="modal-header"> <a href="#" class="modal-close">&times;</a> </div>
      <div class="modal-content-1 hide"> Hello from modal 1 </div>
      <div class="modal-content-2 hide"> Hello from modal 2 </div>
    </div>
  </div>
</div>
<script>
      window.onload = function () {
        var openModalLinks = Array.prototype.slice.call(document.querySelectorAll('[data-open-modal]'));
        var closeModal = document.querySelector('.modal-close');
        var modalOverlay = document.querySelector('.modal-overlay');
        var modalInner = document.querySelector('.modal-inner');
        var modalContent = document.querySelector('.modal-inner');
        var modalContent = Array.prototype.slice.call(document.querySelectorAll('div[class^="modal-content-"]'));

        var handleShowModal = function (id) {
		  document.querySelector('body').classList.add('modal-visible');	
          modalOverlay.classList.add('visible');
          modalOverlay.querySelector('.modal-content-' + id).classList.remove('hide');
        }

        var handleHideModal = function (event) {
          modalOverlay.classList.remove('active');
        }

        var handleOpenModal = function (event) {
          var id = event.target.getAttribute('data-modal');

          event.preventDefault();
          modalOverlay.classList.add('active');

          window.setTimeout(handleShowModal(id));
        }

        var handleCloseModal = function (event) {
          if (event.target !== event.currentTarget) {
            return;
          }

          event.preventDefault();
		  document.querySelector('body').classList.remove('modal-visible')	
          modalOverlay.classList.remove('visible');
          modalContent.forEach(function(modal) { modal.classList.add('hide') });

          modalOverlay.addEventListener(
            'transitionend',
            handleHideModal, {
              once: true,
              passive: true
            }
          );
        }

        openModalLinks.forEach(function(link) {  link.addEventListener('click', handleOpenModal) });
        closeModal.addEventListener('click', handleCloseModal);
        modalInner.addEventListener('click', handleCloseModal);
      }
    </script>
</body>
</html>
1 Like

Here’s my findings:

On a Window 8.1:
IE 11 and EDGE - no issues - perfect
FF - prints the model twice
Chrome - print the underlying page under the modal

Windows 10:
IE 11 and EDGE - no issues - perfect
Chrome and FF - prints the modal twice (does not print the underlying page as it did in 8.1)

Can you post the exact code you are using and I will re-check the results on my system (when I get back home) :slight_smile:

It may be that even though the elements have visibility set to none they will still take up the same space on the page and I guess some browsers are just printing a blank sheet as they are not clever enough to realise there is nothing there.

In that case it is probably wise to set a height to zero for all elements when the print sheet is active apart from the elements in the modal.

Here is a full revised code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal demo</title>
<style>
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.modal-overlay {
	position: fixed;
	top:0;
	left:0;
	display: none;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, .5);
	opacity: 0;
	transition: opacity .2s ease;
}
.modal-overlay.active {
	display: table;
}
.modal-overlay.visible {
	opacity: 1;
}
.modal-inner {
	display: table-cell;
	vertical-align: middle;
}
.modal-container {
	margin: 0 auto;
	width: 50%;
	min-width: 750px;
	max-width: 850px;
	max-height: 600px;
	overflow: auto;
	border: 1px solid;
	background: #fff;
	border-radius: 5px;
}
.modal-header {
	text-align: right;
}
.modal-close {
	margin-right: .25em;
	color: inherit;
	text-decoration: none;
	font-size: 2rem;
	font-weight: bold;
}
.modal-content {
	padding: 0 10px;
}
.modal-content p {
	margin: 0 0 1em;
}
.hide {
	display: none;
}
p.open {
	margin: 1em;
	text-align: center;
	font-size: 1em;
	font-weight: 600;
	color: #4c659b;
	text-transform: uppercase;
	font-family: Arial, Helvetica, sans-serif;
}
@media print {
	html,body{background:#fff!important;color:#000!important;}
	body.modal-visible  * {visibility:hidden!important;height:0;overflow:hidden;}
	body.modal-visible  .modal-overlay, body.modal-visible .modal-overlay * {visibility:visible!important;height:auto;overflow:visible;}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;height:auto;background:#fff;}
	.modal-container{border:none;width:auto;height:auto;min-width:0;max-width:none;max-height:none;border-radius:0;overflow:visible}
	.modal-header{display:none;}
}



</style>
</head>
<body>
<a href="#" data-open-modal data-modal="1">Modal 1</a><br>
<a href="#" data-open-modal data-modal="2">Modal 2</a>
<p>test</p>
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
<div class="modal-overlay">
  <div class="modal-inner">
    <div class="modal-container">
      <div class="modal-header"> <a href="#" class="modal-close">&times;</a> </div>
      <div class="modal-content-1 hide"> Hello from modal 1 </div>
      <div class="modal-content-2 hide"> Hello from modal 2 </div>
    </div>
  </div>
</div>
<script>
      window.onload = function () {
        var openModalLinks = Array.prototype.slice.call(document.querySelectorAll('[data-open-modal]'));
        var closeModal = document.querySelector('.modal-close');
        var modalOverlay = document.querySelector('.modal-overlay');
        var modalInner = document.querySelector('.modal-inner');
        var modalContent = document.querySelector('.modal-inner');
        var modalContent = Array.prototype.slice.call(document.querySelectorAll('div[class^="modal-content-"]'));

        var handleShowModal = function (id) {
		  document.querySelector('body').classList.add('modal-visible');	
          modalOverlay.classList.add('visible');
          modalOverlay.querySelector('.modal-content-' + id).classList.remove('hide');
        }

        var handleHideModal = function (event) {
          modalOverlay.classList.remove('active');
        }

        var handleOpenModal = function (event) {
          var id = event.target.getAttribute('data-modal');

          event.preventDefault();
          modalOverlay.classList.add('active');

          window.setTimeout(handleShowModal(id));
        }

        var handleCloseModal = function (event) {
          if (event.target !== event.currentTarget) {
            return;
          }

          event.preventDefault();
		  document.querySelector('body').classList.remove('modal-visible')	
          modalOverlay.classList.remove('visible');
          modalContent.forEach(function(modal) { modal.classList.add('hide') });

          modalOverlay.addEventListener(
            'transitionend',
            handleHideModal, {
              once: true,
              passive: true
            }
          );
        }

        openModalLinks.forEach(function(link) {  link.addEventListener('click', handleOpenModal) });
        closeModal.addEventListener('click', handleCloseModal);
        modalInner.addEventListener('click', handleCloseModal);
      }
    </script>
</body>
</html>

I suggest you check that exact code in your various browsers before you copy into your own page and then check it works. I only have windows 10 but the results in IE11, Edge, Chrome and Firefox are all the same and just print one page and the modal text only.

1 Like

Paul,

Absolutely perfect in Windows 8.1 and 10. Works the same in all browsers and prints only once and doesn’t print the underlying page. Scrolled modals print the entire content on the modal.

Thank you and James too for now making an easy move out of onclick="window.open resized windows. You have made the modal the way I personally think it should be.

I really appreciate your expertise and the time you took to make that happen.

Take care!

1 Like

Paul,

In changing out my onclick window.opens, I had a long (2 pages) rather than the normal 1 page or shorter scrolling modal of information. In IE and Chrome it cut the printing off to just 1 page and in FF it came up with a blank page (no print at all). Do you see a fix or that?

Thanks

Can you give a demo of the code you are using and I’ll take a look in the morning. Or tell me what to add to my demo to replicate the issue.

I’ll have a look anyway and see if I can replicate the problem using more content.

The code is a straight copy and paste from your last post. The only difference that I noticed is if the content is longer than a page it cuts it off and doesn’t print page 2 and as I mentioned, with FF it just prints a blank page. (unless you cut out some of the text) (see comment below)

I experimented with it by shortening the text in the modal down to one page and it does fine. Therefore, it must be the length beyond that one page.

Thanks again.

Ah ok I see the problem. I forgot to remove the position:fixed from the modal when printing as position:fixed never escapes the viewport so will only print on one page. Change the position:fixed to position:absolute and we should be good to go.

I also negated the line-height to kill some white space The css now looks like this:

@media print {
	html,body{background:#fff!important;color:#000!important;}
	body.modal-visible  * {visibility:hidden!important;height:0;overflow:hidden;line-height:0;}
	body.modal-visible  .modal-overlay, body.modal-visible .modal-overlay * {visibility:visible!important;height:auto;overflow:visible;line-height:normal;}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;height:auto;background:#fff;}
	.modal-container{border:none;width:auto;height:auto;min-width:0;max-width:none;max-height:none;border-radius:0;overflow:visible}
	.modal-header{display:none;}
	.modal-overlay{position:absolute;top:0;left:0;}
}

We can simplify the whole thing if you put a wrapper around the whole page content but keep the modals separate and then you can just set the wrapper to display:none which will allow the modal to be styled without any cascading styles (apart from the original styles of course.)

This simplifies the process a little and makes it easier to manage.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modal demo</title>
<style>
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.modal-overlay {
	position: fixed;
	top:0;
	left:0;
	display: none;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, .5);
	opacity: 0;
	transition: opacity .2s ease;
}
.modal-overlay.active {
	display: table;
}
.modal-overlay.visible {
	opacity: 1;
}
.modal-inner {
	display: table-cell;
	vertical-align: middle;
}
.modal-container {
	margin: 0 auto;
	width: 50%;
	min-width: 750px;
	max-width: 850px;
	max-height: 600px;
	overflow: auto;
	border: 1px solid;
	background: #fff;
	border-radius: 5px;
}
.modal-header {
	text-align: right;
}
.modal-close {
	margin-right: .25em;
	color: inherit;
	text-decoration: none;
	font-size: 2rem;
	font-weight: bold;
}
.modal-content {
	padding: 0 10px;
}
.modal-content p {
	margin: 0 0 1em;
}
.hide {
	display: none;
}
p.open {
	margin: 1em;
	text-align: center;
	font-size: 1em;
	font-weight: 600;
	color: #4c659b;
	text-transform: uppercase;
	font-family: Arial, Helvetica, sans-serif;
}

@media print {
	html,body{background:#fff!important;color:#000!important;}
	body.modal-visible  .wrap {display:none!important}
	body.modal-visible  .modal-overlay, body.modal-visible .modal-overlay * {height:auto;overflow:visible;}
	.modal-overlay,.modal-inner,.modal-container {display:block;width:auto;height:auto;background:#fff;}
	.modal-container{border:none;width:auto;height:auto;min-width:0;max-width:none;max-height:none;border-radius:0;overflow:visible}
	.modal-header{display:none;}
	.modal-overlay{position:static;}
}

</style>
</head>
<body>
<div class="wrap"> <a href="#" data-open-modal data-modal="1">Modal 1</a><br>
  <a href="#" data-open-modal data-modal="2">Modal 2</a>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
</div>

<!-- keep modals outside of wrap -->
<div class="modal-overlay">
  <div class="modal-inner">
    <div class="modal-container">
      <div class="modal-header"> <a href="#" class="modal-close">&times;</a> </div>
      <div class="modal-content-1 hide">
        <p> FirstHello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1</p>
        <p>Hello from modal 1 last</p>
      </div>
      <div class="modal-content-2 hide">
        <p>First Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2</p>
        <p>Hello from modal 2 last</p>
      </div>
    </div>
  </div>
</div>
<script>
      window.onload = function () {
        var openModalLinks = Array.prototype.slice.call(document.querySelectorAll('[data-open-modal]'));
        var closeModal = document.querySelector('.modal-close');
        var modalOverlay = document.querySelector('.modal-overlay');
        var modalInner = document.querySelector('.modal-inner');
        var modalContent = document.querySelector('.modal-inner');
        var modalContent = Array.prototype.slice.call(document.querySelectorAll('div[class^="modal-content-"]'));

        var handleShowModal = function (id) {
		  document.querySelector('body').classList.add('modal-visible');	
          modalOverlay.classList.add('visible');
          modalOverlay.querySelector('.modal-content-' + id).classList.remove('hide');
        }

        var handleHideModal = function (event) {
          modalOverlay.classList.remove('active');
        }

        var handleOpenModal = function (event) {
          var id = event.target.getAttribute('data-modal');

          event.preventDefault();
          modalOverlay.classList.add('active');

          window.setTimeout(handleShowModal(id));
        }

        var handleCloseModal = function (event) {
          if (event.target !== event.currentTarget) {
            return;
          }

          event.preventDefault();
		  document.querySelector('body').classList.remove('modal-visible')	
          modalOverlay.classList.remove('visible');
          modalContent.forEach(function(modal) { modal.classList.add('hide') });

          modalOverlay.addEventListener(
            'transitionend',
            handleHideModal, {
              once: true,
              passive: true
            }
          );
        }

        openModalLinks.forEach(function(link) {  link.addEventListener('click', handleOpenModal) });
        closeModal.addEventListener('click', handleCloseModal);
        modalInner.addEventListener('click', handleCloseModal);
      }
    </script>
</body>
</html>

That would be my preferred approach if the modals are separate from .wrap and not entwined in the html.

You have to remember with print stylesheets to undo any floating or positioning or fixed height and widths etc and try and simplify things for print.