0

Anyone have idea how can I hide text, date or something on page, but when I click button for window.print() show it there? I'm using:

@media print {
  @page { margin: 0; }
  body { margin: 1.6cm; }
}

@media print {
  .hide-from-printer{  display:none; }
}
<a href="#" onClick="window.print()" class="btn btn-success hide-from-printer">Print</a>

So like this button class="hide-from-printer", it shows on page but hide from printing page. I want to do vice versa (on the contrary). Any suggestion?

GSerg
  • 76,472
  • 17
  • 159
  • 346
proofzy
  • 627
  • 1
  • 12
  • 23
  • 1
    Possible duplicate of [How to hide a CSS media query from print? "not" logical operator does not work](http://stackoverflow.com/questions/10591273/how-to-hide-a-css-media-query-from-print-not-logical-operator-does-not-work) – Vadim Ovchinnikov Jan 14 '17 at 07:53

2 Answers2

3

Use this way:

.hide-from-page { display:none; } /* hide at normal page view */

@media print {
  .hide-from-page { display:inline; } /* make it visible during print */
}

Note: its obvious to rename the class to mean correctly (instead of hide-from-printer, it must be something like as hide-from-page or show-only-at-print)

S.Serpooshan
  • 7,608
  • 4
  • 33
  • 61
1

you can use ´screen´ for regular screens so all you would have to do is

@media screen {
    .hide-from-screen {
        display: none;
    }
}

@media print {
     .hide-from-printer {
          display: none;
      }
 }

and use those classes accordingly.

zola
  • 5,737
  • 8
  • 33
  • 48