Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing only one <div> from an html file using css print

Status
Not open for further replies.

rambleon

Programmer
Mar 6, 2004
130
IL
Hi
Is it possible using css - media="print" - to print only a specific <div> element from an html file. If so how does the print class look?
Thanks for any help

Rambleon
 
Just put [tt]display: none;[/tt] to all (*) and then give your div [tt]display: block;[/tt]. I don't know if it will work as simply, but the general idea would be:
Code:
* {
  display: none;
}

div.MyPrintedDiv {
  display: block;
}
Depending on the structure of your code, the whole process might be more difficult. For the code to work, your div must have a class set to [tt]class="MyPrintedDiv"[/tt].
 
Thanks for the reply. The idea is that I want to be able to print parts of the (html) document each part will have a print button which when pressed will only print that <div>. If I take your idea and create a div.MyPrintedDiv1, div.MyPrintedDiv2, div.MyPrintedDiv3 ect for each section I want to print, will it work?

 
The problem with the above is I don't know what the command is that accompanies the print button - "print MyPrintedDiv1" ?
 
I'm likely to have to handle a similar requirement soon. Did any of you guys find a workable solution?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top