Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make table cell shrink according to the content?

How can I make the table with 2 columns (cells) look like this:

  • First cell is shrink according to the content
  • The other cell fits the rest of the table (wider than both contents together)

Example:

<table style="width: 500px;">    <tr>       <td>foo</td>       <td>bar</td>    </tr> </table> 

I need the table to look like this:

.___________________________________________________________________________. | foo | bar            <a lot of space here>                                | |_____|_____________________________________________________________________|                            500 px total width 

Notice: I don't know the width of "foo" so I cannot set "50px", "10%" or something like that.

like image 692
Pavel S. Avatar asked Jul 10 '12 12:07

Pavel S.


People also ask

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

In "Table Tools" click the [Layout] tab > locate the "Cell Size" group and choose from of the following options: To fit the columns to the text (or page margins if cells are empty), click [AutoFit] > select "AutoFit Contents."

How do you auto adjust table td width from the content?

remove all widths and add . content-loader table tr td { white-space: nowrap; } ? Since you have a fixed width for the container, you have too many fields inside of it to fit properly. If you had less it probably would have adjusted on its own.

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 make table cells smaller in HTML?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.


1 Answers

Set the width to anything near zero, to shrink it, then set the white-space to nowrap. Solved.

td { width:0.1%; white-space: nowrap; }  
like image 180
Nat Julian Belza Avatar answered Sep 21 '22 08:09

Nat Julian Belza