Forum Moderators: not2easy

Message Too Old, No Replies

Print stylesheet for an embedded table

What if I only want one table to print?

         

coopster

3:22 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm implementing a form for a site that is a table layout. And I mean tables. The content is laid out something like this but much worse:

+------------------------------+
¦ ¦
+------------------------------+
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
+------------------------------+
¦ ¦ ¦
+------------------------------+

I don't want anything else to print on the page except the table in the middle right of the page. The HTML has no selectors defined such as id or class, except for the <td> in which my content resides. A mock up of the HTML is something as follows:
<table> 
<table>
<table>
<table>
<tr>
<td>
<table>
<!-- This is the left middle table -->
</table>
</td>
<td class="mytable">
<table>
<!-- This is the right middle table -->
<!-- We want only this section to print -->
</table>
</td>
</tr>
</table>
</table>
</table>
</table>

I am struggling with how to tell the stylesheet to not print tables, except the td in the table that I desire. Is this an impossible feat without some form of selectors or am I just looking at this from the wrong angle?

coopersita

5:45 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



Can you have a second copy of the part you want to print at the bottom of the page and set it to display: none for screen, and in the print style set table to display:none?

madcat

6:11 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What happens when you just go about applying a print style sheet as normal?

mrhoo

9:05 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



media="print";
*{display:none}
.myClass td {display:table-cell}
.myClass td table{display:table}
.myClass td table td{display:table-cell}
.myClass td table tr{display:table-row}

coopster

4:19 pm on Mar 31, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That was how I first went about it, mrhoo -- but for some reason the middle right is still coming up blanks on a print option. It's like the global
* {display: none;}
just carries throughout the entire print option, disregarding any rules after that.

coopersita, interesting concept but that would be a lot of bytes to push through bandwidth for really no purpose except a print option.

madcat, I'm not sure I understand what you mean? It just prints out all the navigation and graphics on the top, left and bottom of the page if it is just a *normal* print option. I want to suppress those sections.

coopster

7:19 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think I understand what is happening now. If I work my way from the "inside out" I can get the left portion to be suppressed and the right portion to print. The downside is that the header and footer still print too (all the navigational stuff). However, if I try to suppress them, it suppresses everything and I assume that is because it is all embedded in the first table (and every other stinking table after that!).
<html><head> 
<title>Test</title>
<style type="text/css" media="all">
table {
border: thin solid red;
padding: 5px;
}
.myClass table {
border: thin solid green;
}
</style>
<style type="text/css" media="print">
/*
* { display: none; }
*/
body table table table td table { display: none; }
body table table table td.myClass table { display: block; }
</style>
</head>
<body>
<table><tr><td>
<table>
<tr><td>Header</td></tr>
<tr>
<td>
<table>
<tr>
<td>
<table>
<tr><td>DO NOT PRINT</td></tr>
</table>
<table>
<tr><td>ANY OF THESE</td></tr>
</table>
<table>
<tr><td>TABLES AT ALL</td></tr>
</table>
</td>
<td class="myClass">
<table>
<tr><td><p>PRINT</p><p>ONLY THIS</p><p>ENTIRE TABLE</p></td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr><td>Footer</td></tr>
</table>
</td></tr></table>
</body>
</html>

I'm guessing there is no way to print only the section in green and suppress everything else because of the embedded tables.