0

I have a table whose width is 80% of screensize. This table contains my menu items. Menu items are in the form of table cells. The design I want is that each cell should only be as wide as the text inside it. But I also want a last cell, that will be empty and be as wide as the remaining space in the table. I.E I want the last to inherit the width of the table (remaining space).

But, all the cells get stretched when I increase table width instead of them just fitting to their text.

How do I stop this from happening?

  1. I want all but last of the cells to exactly fit their text.
  2. I want the last cell to take up all the remaining space.

Thanks!

animuson
  • 53,861
  • 28
  • 137
  • 147

2 Answers2

3

Extend the last cell to occupy full width:

td:last-child {
    width: 100%;
}

…and, if you want to make sure the text in the other cells doesn't collapse:

td {
    whitespace: nowrap;
}

Demo here:

http://jsfiddle.net/barney/kz77m/

Barney
  • 16,181
  • 5
  • 62
  • 76
  • It'll work some kind of better, too ;) — `table-cell` display properties (height stretched to fit, vertical alignment, etc) are quite unique, so setting the last cell to display `inline` has plenty of nasty side-effects. – Barney Mar 01 '13 at 09:34
0

It's simple via CSS. You just modify the display style to inline.

Attached fiddle: http://jsfiddle.net/CZYSa/

Nick Andriopoulos
  • 10,313
  • 6
  • 32
  • 56