if I hide a <tr> or <td> in regular stylesheet, how do I show it afterwards (in print stylesheet)? display:block? display:inline, display:inline-table?
or for any other case, like hiding and showing dynamically… what’s default setting for display property for <tr> and <td>??
I haven’t tested it but I’d say the default for <tr> is display: table-row , and for <td> it is display: table-cell When I say I didn’t test it I mean I didn’t create an example to test, I know the actual display values do exist
You could always use a specific Print media style sheet and a Screen media style sheet with differing rules, etc. The table row and table data cell must be contained somewhere within the TABLE.
The TR would equate to: tr { display: table-row; } and the TD would be: td { display: table-cell; } like Remon mentioned.
IE6 and 7 don’t understand the display:table properties and you would need to use display:block (or perhaps inline) to reveal the element otherwise it stays as display:none.
e.g.
tr.hide{display:none}
tr.show{display:table-row}
* html tr.show{display:block}
*+ html tr.show{display:block}
You could always use a specific Print media style sheet and a Screen media style sheet with differing rules, etc.
I end up with a LOT less code this way. Instead of undoing everything inherited from screen sheet, I keep screen and print separate: they both start out at 0.
^I’ve always wondered… if IE has issues with display: table/row/etc when you set it manually in the CSS (but apparently not by default), does IE do ok when Javascript says “use the default display state”?
when I set the display style to an empty string in javascript I find (and I actually found this out on another forum) the display style for that element returns to the browser’s default display style for that element.
the issue came up when someone in js was setting the display style of a <tr> to none to hide it and then wondered why it wouldn’t reappear when they set the <tr> to block.
the solution someone suggested was setting the display style of the <tr> to ‘’ (empty string) and the browser would then set the display style of the <tr> to whatever the browser default is for a <tr> and then the <tr> would reappear.
a <tr> can’t be displayed as a block level element and that is why display block didn’t work.
as far as I can tell this works in all the major browsers.
If we talk about <tr> alone, and about a IE solution, there is a CSS solution. Wrap the <tr> in a <tbody> (remember, you can have as many <tbody> in a <table> as you want) and play with it.
I did an example, a rushed one, I’m at work now. For the last table I didn’t make a js code to change the class, I just put the two class values for it. With a little change, this <tbody> solution can be made to work for all UAs. All you have to do is to remove the * in the selector for them. That one is for IE.
But, as pointed out before, for the other UAs you have better, more natural options: display: table, table-row, table-cell. One that seems to escape the mind of those contributing to this thread is floating. Floating doesn’t change the display completely, so a float:left, a position outside the viewport and a float:none afterwards should preserve the core display attributes for the table elements. For IE floating is useless though.
/* hide a table row */
#row1,#row3{display:none}
/* and in the print stylesheet restore the row */
#row1,#row3{display:block}/* ie6 and 7*/
#row1,#row3{display:table-row}
/* hide a table cell */
#cell2,#cell4{display:none}
/* and in the print stylesheet restore the cell*/
#cell2,#cell4{display:block}/* ie6 and 7*/
#cell2,#cell2{display:table-cell}
The whole point of my exercise was: how to do it w/o resorting to the display rule. For IE one could use <tbody> with positioning and * selector, for the other UAs <tbody> with positioning… or floated and positioned! That way you can also have an empty space instead of the element, as a remainder that there is an element removed from there. This thing may come in handy. Take a look at the following code in IE8.
While many, when making the transition from tables layout, consider each <td> or <tr> a <div>, they forget that <tbody> is more like it to be replaced with a <div> element, if we consider <table> to be <body>. <tbody> does that: provides a way to add structure. And floating <tbody>s, hiding or displaying them, makes for quite interesting features Too bad IE lte 7 doesn’t behave with the floating thing.
As far as hidding the <td>, I believe hidding its content alone is more appropriate.
Well, I was about going to propose that to be a quiz, but then changed my mind
I wanted to show how tables, though overused and misused, are not properly understood at their very basic structure. I’m always surprised how many overlook the <tbody> as an element to give structure to tables content and what you can do with it.
And I wanted to point out the use for relative positioning and the initial space remaining as “occupied” when using it on elements.
Two things that seem never to be pointed enough times
Too bad [IE lte 7] doesn’t want to float <tbody>. And too bad IE8 doesn’t want to float <tr>. Or any other UA.
I’m always surprised how many overlook the <tbody> as an element to give structure to tables content and what you can do with it.
I seem to recall that, because browsers assume a tbody even when you don’t explicitly set one (like it would with body and html tags if you left them out), that javascript actually still has access to table.tBodies (I think it’s called that… I don’t do much with tables and JS).