Forum Moderators: not2easy

Message Too Old, No Replies

How to print a css table

         

zonkd

10:15 am on Oct 7, 2004 (gmt 0)

10+ Year Member



Timetables for students and staff appear on a website I manage. The timetables live inside CSS tables.

It would be handy for browsers to click on something to have a print off of a timetable. Is there a way to do this, please, craftsfolk?

Hester

10:35 am on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you mean by CSS tables? Divs?

whoisgregg

10:52 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you want to print just a certain portion of a page? Put all of your non-printing areas inside of two divs with a class="dontPrintMe" then add this to the head of your document AFTER your existing CSS styling.

<style type="text/css" media="print">
<!--
.dontPrintMe {
overflow: hidden;
visibility: hidden;
display: none;
}
body {overflow:hidden;}
-->
</style>

Then add a handy clickable print button for your js enabled printing browsers (non js enabled folks get a message so they know printing is optimized for what they want):

<script type="text/javascript">
<!--
if (window.print) {
document.write("<a href='javascript:window.print();'>Print This Timetable!</a>");
}
//-->
</script>
<noscript>Printing this page will automatically print just the timetable.</noscript>

whoisgregg

10:56 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may also want to remind your windows IE users to change their default page margins from the 1" margin to a more suitable .5" margin. Why does IE ship with such a huge printing margin?

zonkd

8:34 am on Oct 8, 2004 (gmt 0)

10+ Year Member



Trying this, Whoisgregg. Back soon.

Hester, yes tables that are defined by css rather than the Meccano set-like tables from the Dark Ages. Cheers

zonkd

2:49 pm on Oct 8, 2004 (gmt 0)

10+ Year Member



Whoisgregg

The major problem with this is that the closing of the div class="DontPrintMe" upsets the page.

The table to be printed is at the bottom of the page. So the DontPrintMe area stretches from <body> to the table. The </div> placed here, ends the layout for the page, rather than to close the DontPrintMe area.

I suppose there is no other way to close the DontPrintMe area.? Cheers

whoisgregg

8:03 pm on Oct 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You probably have invalidly nested divs (given your css rules). Like a body div that is being ended prematurely now...? If you'd like to sticky me a url, I'd be happy to look at the code or you can post a simplified snippet here for us to debug. :D

Without seeing the code, it would be hard to troubleshoot. What I can tell you is that I have a page with this structure that works perfectly:

<body>
<div class="dontPrintMe">
...bunch of stuff...
</div>
<div class="printMe">
...bunch of stuff...
</div>
</body>

The .printMe class has no special rules for printing (other than fixed width).

zonkd

2:22 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



Sorry for the delay, Whoisgregg.

Yes, I suspect you are right. Both dreamweavers I work with tend to be temperamental. When things don't work one way, I often try to find an alternative - rather than have it crash about the ungraceful ears.

What I did was to put the timetables onto a 'printer friendly page' which in this case is a euphemism for a page with almost nothing but the timetables. It seems to be working well.

I've copied your advice and I will try this again the next time. Many thanks, Whoisgregg.

whoisgregg

5:09 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to offer what (little) knowledge I have. :D