Handle Printing Data with HTML using CSS

Posted By  pranay rana On 27 Mar 2011 07:03:37
emailbookmarkadd commentsprint
No of Views:713
Bookmarked:0 times
Votes:0 times

Introduction

In this tips, i going to share with you, how to handle the HTML Data to printing using CSS.Now days many websites offer printing features to user,what they are seeing currently in the browser.

This tips will help to you, how to ignore unnecessary contents(like ads,image,profile and etc),when users print content.

Problem

In my project I need to implement functionality where I have to print Order print receipt. But the real thing is I have to hide some part of page when I print page i.e hide  and I have to use same page for this.

Solution

The easy solution for this problem is you need to give one more style sheet for the print purpose by which you can hide those element which are not required. For this you require to use attribute

media = print

of the STYLE element. Following is small code for this issue

<style media="screen">
  .noPrint{ display: block; }
  .yesPrint{ display: block !important; }
</style>
<style media="print">
  .noPrint{ display: none; }
  .yesPrint{ display: block !important; }
</style>

or when you linking style sheet

<link css="" href="ScreenStyleSheet.css" media="screen" rel="stylesheet" type="" text="">
<link css="" href="PrintStyleSheet.css" media="print" rel="stylesheet" type="" text="">

Summary

So by using media type as print you can print only those element that you want. Even you can print element with the different style.

 

Sign Up to vote for this article
Other popular Tips/Tricks
    Comments
    There is no comments for this articles.
    Leave a Reply
    Title:
    Display Name:
    Email:
    (not display in page for the security purphase)
    Website:
    Message:
    Please refresh your screen using Ctrl+F5
    If you can't read this number refresh your screen
    Please input the anti-spam code that you can read in the image.
    ^ Scroll to Top