2

I have a div that contains: text , backround color, image

and i want to print only this div.

I'm kind of clueless so any help could help

thanks.

Daerik Fisher
  • 293
  • 3
  • 11
  • 20

3 Answers3

6

You need to define a print stylesheet. You do this in the following manner:

<link rel="stylesheet" href="your url" type="text/css" media="print" />

In that sheet you specify how to display your website for the printed page. So what you can do is set every element to display:none except for the div you wish to print.

You can do this easily with the following selectors:

* {
    display: none;
}

#printDiv {
    display: block;
}

and simply apply the id printDiv to the div you wish to print.

Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
3

What have u tried?

Maybe this helps:

You require to create new style sheet print.css and set CSS media=print

for example :

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

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

Giv the specific div the .yesPrint class and all other the .noPrint.

Denny Mueller
  • 3,505
  • 5
  • 36
  • 67
1

I have recently used this JQuery plugin to do something similar

http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/

lostsource
  • 21,070
  • 8
  • 66
  • 88
  • Guys finding this at 2015 or newer, the printElement uses $.browser which is removed from jquery since v1.9 and won't work. – Chaibi Alaa Dec 24 '15 at 01:47