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?
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?
You need some css for that
#printOnly {
display : none;
}
@media print {
#printOnly {
display : block;
}
}
@media screen
{
#printOnly{display:none;}
}
@media print
{
#printOnly{}
}
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
You can attach external css stylesheet with media="print"
attribute:
<link rel="stylesheet" type="text/css" media="print" href="print.css">
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>
/*for printer*/
@media print {
#printOnly { }
/* write your css rules*/
}
/*for desktop*/
@media screen {
#printOnly { display: none;}
/*for all display view*/
}
@media screen { #printOnly:{display:none;} }
@media print{ #printOnly:{display:block;} }
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;
}
}