Twitter Bootstrap: Print content of modal window

前端 未结 10 984
走了就别回头了
走了就别回头了 2020-11-28 02:19

I\'m developing a site using Bootstrap which has 28 modal windows with information on different products. I want to be able to print the information in an open modal window.

10条回答
  •  清酒与你
    2020-11-28 02:41

    Heres a solution with no Javascript or plugin - just some css and one extra class in the markup. This solutions uses the fact that BootStrap adds a class to the body when a dialog is open. We use this class to then hide the body, and print only the dialog.

    To ensure we can determine the main body of the page we need to contain everything within the main page content in a div - I've used id="mainContent". Sample Page layout below - with a main page and two dialogs

    
     
    main page stuff

    Then in our CSS print media queries, I use display: none to hide everything I don't want displayed - ie the mainContent when a dialog is open. I also use a specific class noPrint to be used on any parts of the page that should not be displayed - say action buttons. Here I am also hiding the headers and footers. You may need to tweak it to get exactly want you want.

    @media print {
        header, .footer, footer {
            display: none;
        }
    
        /* hide main content when dialog open */
        body.modal-open div.container.body-content div#mainContent {
            display: none;
        }
    
        .noPrint {
            display: none;
        }
    }
    

提交回复
热议问题