tags:

views:

153

answers:

1

It's a classic problem - when you have an empty table cell the browser doesn't render borders around it. There are also two well-known workarounds. One is to place an   in the table cell; the other is to use the empty-cells:show CSS property.

Unfortunately both have drawbacks.   is kind of ugly when it comes to selecting text and copy-pasting it. You get a lot of spaces where there shouldn't be any, perhaps even with an exotic Unicode character. empty-cells:show should address exactly this problem, but unfortunately it only works properly in IE starting with version 8 (and then only in standards-compliant mode). It can be made to work in other versions by also specifying border-collapse: collapse, but sometimes this is what is NOT desired. In my case I have a fairly complex table and it relies on border-collapse:separate and would otherwise create quite a messy CSS/HTML soup.

So what are other things that you might put in a table cell that would make IE draw the borders yet not be visible or copyable? For all other browsers the empty-cells:show already does the trick, so I really just need to fool IE.

+3  A: 

You can also put invisible br element:

<td><br style="visibility:hidden"/></td>

It is ridiculous amount of unnecessary code, but it makes the trick - no additional text added yet cell is displayed.

Sergey Ilinsky
Of course you can define a CSS class .e{visibility:hidden} and write <br class="e" />, or, alternatively, if don't have other meaningful br elements in the table, define a style "table br {visibility:hidden}"
Sergey Ilinsky
How does <br style="visibility:hidden"/> differ from <br> ? Both allocate the space and both display nothing else.
Alohci
Try selecting table cell contents in IE6 with visibility set to hidden and without it. When it is set cell does not seem to get selected (at least visualy). This is exactly what the person who asked question wanted.
Sergey Ilinsky
Hmm yes, I see. Thanks. Not quite *exactly* what the OP asked though, as the carriage returns are still copied even though they're not visible when selected.
Alohci