farzad farzad - 18 days ago 5
jQuery Question

why css omitted in print area

I have a issue with print area from page . when i try print whole page structure is work with css but when i want print area , css not work and omitted . why ?

I use bootstrap 3 and i fired print by this code :

$(document).on('click','#print', function(){
w=window.open();
w.document.write($(this).parents('.panel').find('.panel-body').html());
w.print();
w.close();
});


I try this css but not work .

@media print {
body * {
visibility: hidden;
}
table, table * {
visibility: visible;
direction:rtl;
}
table {
position: absolute;
left: 0;
top: 0;
}
}

Answer

You probably just need to add the style element (with the media print) to the html you are generating in the print window. Also, you should consider if you need any other css applied to the print document. You are copying some elements of the current page, but not the css.