Reputation: 14145
Let's say that I have
<div id="printOnly">
<b>Title</b>
<p>
Printing content
</p>
</div>
Is it possible to hide this div when page rendering and to show only when printing this div?
Upvotes: 13
Views: 15609
Reputation: 280
In case, display: none
is not working or creating issues with the print layout. You can use this
@media screen {
.print-only {
visibility: hidden;
position: absolute;
z-index: -199;
transform: scale(0.1);
}
}
@media print {
.print-only {
display: flex;
overflow: visible;
transform: scale(1);
}
}
Upvotes: 0
Reputation: 271
You need media query for switching between print and screen option
@media screen { /* for screen option*/
p {
font-family: verdana, sans-serif;
font-size: 17px;
}
}
@media print { /* for print option*/
p {
font-family: georgia, serif;
font-size: 14px;
color: blue;
}
}
http://www.w3schools.com/css/css_mediatypes.asp
Upvotes: 0
Reputation: 2044
@media screen { #printOnly:{display:none;} }
@media print{ #printOnly:{display:block;} }
Upvotes: 1
Reputation: 51
/*for printer*/
@media print {
#printOnly { }
/* write your css rules*/
}
/*for desktop*/
@media screen {
#printOnly { display: none;}
/*for all display view*/
}
Upvotes: 1
Reputation: 4956
@media screen
{
#printOnly{display:none;}
}
@media print
{
#printOnly{}
}
Upvotes: 8
Reputation: 7701
I think the best solution would be to create a wrapper around the non-printable stuff:
<head>
<style type="text/css">
#printable { display: none; }
@media print
{
#non-printable { display: none; }
#printable { display: block; }
}
</style>
</head>
<body>
<div id="non-printable">
Your normal page contents
</div>
<div id="printable">
Printer version
</div>
</body>
Upvotes: 1
Reputation: 1231
You should use media query.
In your case:
#printOnly {
display: none;
}
@media print {
#printOnly {
display: block;
}
}
PS take a look here http://www.joshuawinn.com/css-print-media-query/ for browser support
Upvotes: 5
Reputation: 152206
You can attach external css stylesheet with media="print"
attribute:
<link rel="stylesheet" type="text/css" media="print" href="print.css">
Upvotes: 2
Reputation: 28445
You need some css for that
#printOnly {
display : none;
}
@media print {
#printOnly {
display : block;
}
}
Upvotes: 34