Click to See Complete Forum and Search --> : How to set table width dynamically with CSS??


liongate
10-16-2007, 09:50 PM
I have created a simple page that displays data from a database in a table. The problem is, the cells are only as wide as the largest word in the data field. How can I use CSS to make the cells in the table automatically size to the length of the entire string of text from the data field? It seems like there should be a fairly simple way to do this with CSS. For example, if my (hypothetical) name was all in one field, my table would display my name like this, all in one cell:

Eugene
P.
Huppermittens

Here is the code I am using, which I obtained from the w3schools site:

<table border="1">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs. Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>

Fang
10-17-2007, 04:35 AM
td {white-space: nowrap;}

mthor
10-17-2007, 01:44 PM
maybe this will work, sry don't have time to test it <td width="100%"></td>

liongate
10-17-2007, 02:04 PM
I think Fang's answer is the correct one in this case. Thanks, folks!!