Using CSS to ensure that a long div prints inside a modal without creating a second page in Internet Explorer

Currently, I am in the process of working on a new iteration of the project and encountering issues with the print CSS style implementation.

Here is the link to the old project for reference:

To print, follow these steps:

Click on the wrench button -> printer button -> choose the template. A modal will appear allowing you to print in both portrait and landscape orientations. The printing process involves an iframe and a combination of two CSS stylesheets; one from the main project and another unique to the iframe.

The CSS for printing hides all content except for the modal when printed. Attempting to print directly from the main page results in a blank page.

In this new version, I have omitted the use of iframes due to limitations with maps. While the new method eliminates iframes, Bootstrap now conflicts with the printing functionality.

Initially facing issues with orientation in Chrome and missing pages on other browsers, I discovered that overriding Bootstrap's CSS rules could resolve these problems:

 @page {
   size: auto
 }
 .flex-class {
   display: block;
 }

Despite achieving success with Firefox and Opera, Internet Explorer 11 still presents challenges in printing multiple pages. The following CSS adjustments seem to be disregarded by IE:

#pllegwrapper {
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

#pagesplit {
  display: block;
  page-break-before: always !important;
  break-before: page !important;
}

UPDATE:

I have tried applying display: table to the main div containing the two pages which allows successful printing in IE but not in Firefox.

Answer №1

To ensure proper printing of your model, set its position to relative.

Click here to view the code snippet on Plunker.

/**CSS Styles for Modal Printing**/

@media print {
  body * {
    visibility: hidden;
  }
  #print-content * {
    visibility: visible;
    overflow: visible;
  }
  #mainPage * {
    display: none;
  }
  .modal {
    margin: 0;
    padding: 0;
    min-height: 550px;
    visibility: visible;
    /**Remove scrollbar for printing.**/
    overflow: visible !important;
    position: relative;
  }
  .modal-dialog {
    visibility: visible !important;
    /**Remove scrollbar for printing.**/
    overflow: visible !important;
  }

Answer №2

The issue was resolved by making adjustments to the code snippet below. I eliminated any flex properties and float from #printMod, which represents the bootstrap modal itself. Subsequently, I added display: table to both #printMod and #printBody. The latter serves as the main container within the .modal-body element. It was quite a lengthy process to correct the problem, all due to Bootstrap.

@media print {

  @page {
    size: auto;
  }

  body {
    margin:0 !important;
    padding:0 !important;
    height:100% !important;
    width: 100% !important;
  }
  body * {
    visibility: hidden;
  }

  #printMod,
  #printMod * {
    visibility: visible;
    float: none;
    display: block;
    flex: none !important;
  }

  #printBody {
    display: table !important;
    margin: auto !important;
  }

  #printMod {
    & {
      display: table !important;
      position: absolute;
      left: 0;
      top: 0;
      padding: 0 !important;
      margin: 0 !important;
      width: 100% !important;
      break-inside: auto;
      border: none !important;
      overflow: visible !important;
    }

    .modal-header,
    .modal-footer {
      display: none;
      border: none !important;
    }

    .modal-dialog,
    .modal-content,
    .modal-body {
      display: block;
      overflow: visible;
      height: 100% !important;
      max-height: 100% !important;
      padding: 0;
      border: none !important;
    }

    #plwrapper,
    #pllegwrapper {
      page-break-inside: avoid !important;
      break-inside: avoid !important;
    }

    #pagesplit {
      display: block;
      page-break-before: always !important;
      break-before: page !important;
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to use Boostrap to create a menu that automatically closes when clicking outside of it?

Currently, I am not utilizing JavaScript to toggle the hamburger menu. Instead, I am relying on Bootstrap's built-in functionality for opening and closing it. Here is my HTML code: <div class="container"> <h3 class="brandna ...

In Internet Explorer 8, the background image is disappearing once the page has fully loaded

Check out this website: . Once the page has loaded, the background image disappears in IE8, however it works perfectly fine in Firefox and Chrome. I have tried making edits to the CSS code but the issue persists. Any assistance would be greatly appreciate ...

Create a table that excludes the content of the initial cell

I am seeking to update my table design. The desired look can be found here. Currently, my table looks like this: current table. The key difference I want to achieve is the removal of the first cell (positioned at 0;0) in the desired table design. Additio ...

What is the best way to differentiate between two CSS elements with the same class name?

I ran into an issue where two elements share the same class name, specifically "img" Is it possible to apply different styles to these elements that are nested under different parent classes, despite having the same class name? I am trying to customize t ...

"Upon applying overflow:hidden to the wrapper through jQuery, the window automatically scrolls to the

In my jQuery code, I don't want the window to scroll to the top when my wrapper is set to overflow:hidden. $('#shownav').click(function(event) { $('#wrapper').toggleClass('noscroll'); return false; }); Her ...

Utilizing effective CSS media queries within an Angular application

According to what I've read, it is not recommended in Angular to use the CSS hidden element to hide an element like this: .container{ background-color : powderblue; height : 50px; width : 100% } @media (max-width: 400px){ .container{ ...

Adjust the color of the label when the checkbox is marked, and make it red when the checkbox is left

Looking to create a customized checkbox due to challenges in styling the default HTML checkbox, I have attempted the following code. The checkbox functions properly when clicking on the label, but I am unable to change the border color of the label based o ...

Issue with ASP.NET Form Input - Width behaving differently than expected (not expanding to 100%)

Simple Form Issue: Problem: The width of the <input> element is not expanding to 100% If the class form-control is applied to the element, it should have a width of 100% Screenshot: Output from Visual Studio Utilizing Visual Studio 2017 (MVC5 AS ...

Incorporating Dropzone.js functionality into my website

Hey everyone, I wanted to share about this amazing drop and upload feature that's available as open source on . The CSS and JavaScript are all set up, but for some reason, I'm having trouble getting it to work in my code. I'm pretty new to w ...

What is the best way to divide a web page screen into three equal horizontal sections?

My goal is to split the screen into three equal sections horizontally so that I can place different images in each section. However, despite my efforts, I am encountering issues with white space and unequal division. This is my current setup: HTML: ...

IE9 encounters an error when using jQuery's .remove() function

While testing my website in IE9 using Firebug Lite, I encountered an issue. When attempting to run a basic command to remove a div, I received an error saying "TypeError: Object expected". The command I used was: $("#drag-hoverbox_you").remove(); Interes ...

Background with funky Font Awesome colors

Font Awesome is working perfectly for me, but I'm experiencing an issue with strange borders appearing around the icons in Chrome. Interestingly, this problem doesn't occur in IE and Firefox browsers. What's even more peculiar is that the bo ...

Having issues with customizing the design of MaterialUI Accordion header

Link to my code sandbox project I am encountering issues with the styling in my Accordion Heading. My Accordion Contents are set up like this: <Accordion heading1= { <DishItem name="Döner Teller Spezial" price="13,60€"/> ...

What is the correct method for asynchronously loading CSS files in web development?

On a mission to enhance my website's performance, I set out to achieve the perfect score on PageSpeed Insights. Everything was going smoothly until I encountered an issue with CSS delivery. I initially achieved a flawless result by utilizing the prel ...

How can I transform an array of text into dropdown options?

Currently, while utilizing Vue and vue-bootstrap, I am facing the task of populating a dropdown menu with an array of text items retrieved from my database. The <b-form-select> component in Bootstrap requires objects of the form {value: 'some va ...

What is the best way to desaturate an image using CSS?

Currently on my website, I have an image displayed as follows: <img src="/Images/content/home.png" alt="" style="float: left;"> I am wondering if there is a CSS property that can be applied to desaturate this image without the need to manually edit ...

Customize your Bootstrap navbar with a specific width and perfectly centered position

Using Bootstrap 4, I aim to customize the inline form in the navbar to have a specific width on laptops and extend to the full screen on mobile devices. Here is how it appears on my mobile device: https://i.sstatic.net/gjewu.png https://i.sstatic.net/KJh ...

prettyPhoto popup exceeds maximum width and height limitations

I am currently using the most up-to-date version from No Margin for Errors and I have set allow_resize to true. However, the size of the display is still too large. Is there a way to set a maximum width/height? I have already configured the viewport as fo ...

Safari browser is experiencing issues with the custom file upload script

My custom upload script allows users to easily select images for upload by clicking or dragging them into the designated box. A preview of the chosen image should appear, and this functionality works smoothly in Firefox and Chrome. However, I've encou ...

What is the best way to create a sliding <nav> effect when a <div> is clicked?

Hello! I am looking for a solution that will cause the navigation contents to slide out from the left when the div class "bt-menu" is clicked. It should also slide back in to the left either when the div is clicked again or when anywhere outside of the nav ...