AFAIK, you can't use a specific CSS attribute to control whether an element is printed or not, but you can use CSS media queries instead:
@media screen {
#print-content {
display: none;
}
}
This will prevent the element from rendering when the page is being displayed on a screen, but when it is printed, it will process it normally according to the rest of your CSS rules.
If you want the opposite effect (hide in print, but show on screen), you can use this:
@media print {
#print-content {
display: none;
}
}
See this page for more information on CSS @media queries.
FYI, it's bad practice to use display: none;
to hide the content by default, then use display: block;
to show it in a media query. This is based on the assumption that the element's display type is block
, but it may very be anything else such as inline
, inline-block
, etc. It also uses two rules instead of one.