Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML CSS How to stop a table cell from expanding

Tags:

html

css

I have a table which is built with the contents coming from a returned dataset. What I want to do is stop a 'description' cell from expanding over 280px wide, no matter what the content length (its s string). I have tried:

<td align="left" valign="top" style="overflow:hidden;" nowrap="nowrap" width="280px" > 

But this doesn't seem to work. I don't want it to wrap, nor do I want anything over 280px to be displayed.

like image 207
flavour404 Avatar asked Aug 05 '09 22:08

flavour404


People also ask

How do you stop a cell from expanding in a table?

To prevent cells (rows) from expanding vertically, you have to set a fixed height for table rows. Select the relevant rows and, on the Table Tools Layout tab, click Properties. On the Row tab, select "Specify height" and then choose "Exactly" for "Row height is." Specify the desired amount.

How do I restrict table width in CSS?

The best possible solution for this is the one you are using now. Since you cannot predict the number of columns you cannot set a width to each column. So setting the overflow of the parent div to auto and the child table width to 100% is the best solution.

How do I hide the overflow text in a table cell?

To use the CSS overflow property with its "hidden" value on the HTML <td> element, you need to set the table-layout property with the "fixed" value and an appropriate width on the <table> element. Then, you need to add the overflow property set to "hidden" and white-space property set to "nowrap" on the table cell.

How do I reduce cell space in HTML?

In traditional HTML coding you remove the spacing within a cell by setting the “cellspacing” attribute to zero.


1 Answers

It appears that your HTML syntax is incorrect for the table cell. Before you try the other idea below, confirm if this works or not... You can also try adding this to your table itself: table-layout:fixed.. .

<td style="overflow: hidden; width: 280px; text-align: left; valign: top; whitespace: nowrap;">    [content] </td> 

New HTML

<td>    <div class="MyClass"">        [content]    </div> </td> 

CSS Class:

.MyClass{    height: 280px;     width: 456px;     overflow: hidden;    white-space: nowrap; } 
like image 185
RSolberg Avatar answered Sep 22 '22 17:09

RSolberg