Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make td (cell) from html table expand for the row to fit in one line?

In some html cells (td) the text is wrapped because the size of the column is smaller than the size of the text on the cell. I don't want the text to be wrapped, I want the column width to expand so the wrapping don't happen!

How can I do that?

One final note, I only can use html code, no css :(

like image 931
aF. Avatar asked Jun 01 '12 16:06

aF.


People also ask

How do you make a table row expandable in HTML?

The expandable table can be achieved by using JavaScript with HTML. By Clicking on a row of the table, it expands and a sub-table pops up. When the user again clicks on that row the content will hide. This can be very useful when the data is complex but it is inter-related.

How do I fix TD size in HTML?

By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.

How do I fit text in a table cell in HTML?

Use the border-collapse property set to "collapse" and table-layout property set to "fixed" on the <table> element. Also, specify the width of the table. Then, set the word-wrap property to its "break-word" value for <td> elements and add border and width to them.

How do I make a table fit the contents of a cell?

Automatically adjust your table or columns to fit the size of your content by using the AutoFit button. Select your table. On the Layout tab, in the Cell Size group, click AutoFit.


2 Answers

Confusing question, but I think you might be looking for the colspan="x" attribute.

<table>
   <tr>
      <td>1</td>
      <td>2</td>
   </tr>
   <tr>
      <td colspan="2">fills both columns</td>
   </tr>
</table>
like image 110
Josh Siok Avatar answered Sep 16 '22 12:09

Josh Siok


Since you can't use CSS, how about:

<td nowrap="nowrap">

I'd prefer to use CSS here on the TD (white-space:nowrap) since the nowrap attribute on the TD element isn't supported HTML 4.01 Strict / XHTML 1.0 Strict.

Here's a quick jsFiddle example showing the effect. Take out the attribute and you can see the difference.

like image 31
j08691 Avatar answered Sep 16 '22 12:09

j08691