1

I am having some dynamic content that should be shown only in the printing page and not in the web page using CSS or javascript. Please help me to do this.

For example;

I am having a div content like this..

echo '<div id="noshow">'.$val.'</div>'; //i am using php and $val is a dynamic value.

I need to show this value only in the printing page and not in the browser page. I used display:none. But, I don't know how to make it to display again in the printing page.

3
  • 2
    Put your print-specific styles in @media print { #noshow { display: none; } }. Commented Jun 24, 2015 at 13:46
  • Take a look to this smashingmagazine.com/2011/11/24/… Commented Jun 24, 2015 at 13:47
  • Do you have two sets of CSS? Commented Jun 24, 2015 at 14:05

2 Answers 2

2

In you're regular stylesheet you could use @media queries for your print css...

@media print {
    #hid { display: table-row; }
}

or you could add a print style.css to the head of your page with the media attribute.

 <head>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
</head> 
Sign up to request clarification or add additional context in comments.

4 Comments

It works..but, i am having a table's tr as hidden.. While displaying it in print shows this as a block not as a table's tr.. help me..
say for ex, this is my code <style> @media print { #hid { display:block; } } #hid { display:none; } </style> <?php echo '<table>'; echo '<tr><td>Bye</td></tr>'; echo '<tr id="hid"><td>hai</td></tr>'; echo '</table>'; ?> It hides the hai in both printing view and browser view.. Help me.
i tried all most all property values in this link w3schools.com/cssref/pr_class_display.asp still doesn't work.
for a tr you should show it as a table row. I've updated my answer with the correct display property for you.
-1

You need to have two sets of CSS. One that is specifically around displaying to the browser and one that is for printing.

Look in to http://printstylesheet.dbushell.com/

Cheers Truez

2 Comments

Pasting a link is not an answer. Answer a question with example code.
Aaron, Correct it's not but the answer isn't to just gift the user the answer. One answer is too use two sets of CSS one for printing and one for normal display, the URL just shows a case where the user has hidden any elements within the body section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.