Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cell border when no data is present

Status
Not open for further replies.

dvsmas

Programmer
Jun 20, 2001
16
0
0
US
I would like to know if there is any way to get border for a cell in a table when no data is present in the cell without using nbsp;  in the TD tag.

For all cells in first column, i'm using nbsp;  at the end of the data. Here is the code i'm using (i'm removing & before nbsp; because it doesn't show up in the Preview Post :) So, please add & before nbsp; when actally using it in a .html file):

<Table border=&quot;1&quot; >
<Tbody>
<TR>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in column 1, row 1 here. nbsp;</TD>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 2 here.</TD>
</TR>
<TR>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Data in cell 3 here. nbsp;</TD>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 4 here.</TD>
</TR>
<TR>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 5 here. nbsp;</TD>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 6 here.</TD>
</TR>
<TR>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>nbsp;</TD>
<TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 8 here.</TD>
</TR>
</Tbody>
</Table>

If i dont use nbsp; in the first column of fourth row, i will not get a border for that cell. But if i use nbsp; to get a border, i'm losing &quot;middle&quot; vertical alignment in first column of third row.

Could anyone suggest a way to get a border without use of nbsp; by using CSS or any other way?

TIA

 
Well, you seem to have two issues here.

One is, you say when you use the &nbsp; you are losing vertical alignment in the 1st column of the 3rd row (&quot;cell 5&quot;).

Nope, I don't think so. I think your &nbsp; is simply wrapping to a second line and this two-line-high thing is &quot;middle&quot; aligned as you requested.

Secondly, you want a boder for an empty cell. Well I didn't find anything too great on this. All I can suggest is that you set the TABLE style as in
Code:
style=&quot;border-collapse: collapse&quot;
and see if you like it.

This doesn't get rid of the boder, just changes it in a subtle way. Can't claim it'll work on Netscrape or any moldy version of IE. Give it a shot?
 
Can't you just put a blank image or transparent gif in the first column of the final cell e.g. <img src=&quot;blank.gif&quot; height=&quot;1&quot; width=&quot;1&quot;>.

BTW what dilettante aout the wrapping is true. Insert this code into your table so you can see the effects of setting the spaces out differently. Sorry about the text and don't forget the & ;-))

Code:
  <TR>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 5 here.*space*nbsp;</TD>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>test test test test test test test test test test test test test test test test test test test test test test test test </TD>
 </TR>
  <TR>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 5 here.*nospace*nbsp;</TD>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>test test test test test test test test test test test test test test test test test test test test test test test test </TD>
 </TR>
  <TR>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>Some data in cell 5 here.*nospace or nbsp*</TD>
   <TD width=&quot;150&quot; valign=&quot;middle&quot;>test test test test test test test test test test test test test test test test test test test test test test test test </TD>
 </TR>

Hope this may be of some use.

Regards
Chris
 
The simplest way would be to hard-code an HTML non-breaking space character in the empty table cell, by using the &quot; &nbsp; &quot; syntax. This is common in databse-driven sites, where blank field leave a table incomplete and ugly.

<tr>
<td>&nbsp;</td>
</tr>
 
BTW style=&quot;border-collapse: collapse&quot; doesnt work in Netscape. But style:&quot;empty-cells: show&quot;, shows a border for empty cells in Netscape 6.0. This doesnt work in Internet Explorer.

If jasonslas means to put a &nbsp; for empty cells, how to do it JSP's where i cant determine the content of the cell(without writing if-else loop, i dont want to clutter JSP by putting too much java code):
<TD><%=variableX%></TD>

If variableX holds some text, border will appear otherwise it'll appear blank and no border will appear and looks ugly!

Is there any way of forcing the stylesheet to check for emptiness of a cell which will be compatible for Netscape and Internet Explorer?
 
Will it throw your formatting off too much to just include a space in EVERY cell?
Code:
<TD><%=variableX%>nbsp;</TD>
I've done that one before, though an if-else block would be ideal. It's not cluttered, you could do it all on one line and it wouldn't be bad.
 
Glowball if you refer to cell 5 in the above table, by including &nbsp; in that cell, i get an illusion of loss of &quot;middle&quot; vertical alignment even though browser actually aligns the text and &nbsp;  It happens only on boundary conditions when the data is just sufficient enough to fit the cell.

Thanks

 
Dang...I didn't stop to think that by typing the characters for an HTML on-breaking space it would be interpreted literally by the page.

Here's how my example should have read:

<tr>
<td>&amp;nbsp;</td>
</tr>


This should work. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top