@media print css

Asked

Viewed 15,301 times

8

Maybe these questions can be labeled "idiot", but believe me, I really need to ask this here because I have not found anywhere on the Internet and who can help me I will be very grateful...

Is there any way to do 2 (two) or more "@media print" of css? For example, I made one to print a certain div, now I want to print another totally different div with other formatting settings, as I would using @media print itself?

Taking advantage of the question, there is some way to format the div as desired before having printed by javascript, I did not like the javascript printing, comes almost nothing of what was done on the page other than pure writing. '-'

@media print {
body * {
    visibility: hidden;
}
.noneImprime
{
    display: none;
}
#imprime, #imprime * {
    visibility: visible;
    margin-top: -160px !important;
}
#imprime
{
    width: 1100px;
}
.btn-resultado{
    display: none;
}
@page{
     size: landscape;
    }
}

Above is the code I am using to print my div with the ID: print, however I have another div, which in my case is the content of a modal to print, how do I print only the desired content as it correctly shows above and in the same print print print only the content of my modal? In this case every time I click on the designated button it will always print the same div.

1 answer

12


To format two different div’s, put different classes in it and place the different properties inside the @media print

To test how it works before generating javascript printing you can go to 'More tools > Rendering Settings > Emulate media > print' from the Chrome developer tool:

Sinalização da localização da opção "Render print" dentro da ferramente de desenvolvedor do Google Chrome

You’ll probably have to use some !important to overwrite the standard print sheet style and how you will do this within the print media query, it is quite quiet.

  • I understood Vinicius, thank you very much for the answer, however I have one more question, in my case I use the visibility: Hidden and Visible to show in the print sheet only the desired content, to do this with two different Ivs I think it does not right, why either show one or show the other.

  • Dude, if you can edit your question with the code that makes it easier to understand that, but then it’s a matter of assigning an id or a different class and working with the CSS rules.

  • I edited the post, I don’t think I know how to explain right, anyway I really appreciate your help.

  • Hm, the explanation is a little complicated to understand to be honest, I don’t know if HTML would help, but it wouldn’t just be a matter of forcing a display on the content of the modal?

  • 1

    No, but your answer is correct, thank you for your help, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.