Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format an HTML table using CSS for printing?

Tags:

html

css

I want to format table using CSS to show an attendance sheet. How do I add CSS styles to the table so that it can be printed?

like image 343
Parag Avatar asked Jul 20 '12 04:07

Parag


2 Answers

Within your style sheet, use

@media print {
  /* put your CSS rules if they are to apply in print only */
}

For example,

@media print {
   * { color: black; background: white; }
   table { font-size: 80%; }
}

The details depend on the types of problems you expect to have with printing your specific table. Generally, if you have set fixed column widths (e.g. in pixels), you probably need to reconsider this part of your design. If you are using colors to convey essential information (e.g., red cell standing for absence, green for presence), you need to reconsider this decision.

like image 79
Jukka K. Korpela Avatar answered Sep 28 '22 07:09

Jukka K. Korpela


use following css

table, th, td
{
  border-collapse:collapse;
  border: 1px solid black;
  width:100%;
  text-align:right;
}

also you can use media="print" for print specific layout

like image 22
Hiren Soni Avatar answered Sep 28 '22 08:09

Hiren Soni