tags:

views:

515

answers:

6

How to prevent line-break in a column of table, not a single cell?

A: 

use the nowrap attribute,

<td nowrap="nowrap">...</td>
jnunn
In this context it's not a tag. The `td` is the tag. You meant to say `attribute`.
BalusC
Deprecated presentational attribute. It shouldn't be used.
Xanthir
A: 

Try <nobr>

Jamie
That's old and very invalid.
Xanthir
+2  A: 

You can use the CSS style white-space:

white-space: nowrap;
David M
I want to prevent line-break in a column of a table, not a single cell.
Steven
So add it to every cell in the column?
David M
Add a class to every td cell you want this to apply to, if you don't want it applied to every cell in the table, but just specific ones.
James Black
I want to apply it to all cells of the same column.
Steven
Is there an easy way to do it?
Steven
Steven, have you seen my edit?
BalusC
A: 

Use the nowrap style:

<td style="white-space:nowrap;">...</td>

It's CSS!

Derek Illchuk
I want to prevent line-break in all cells of the same column.
Steven
A: 
<td style="white-space: nowrap">

The nowrap attribute I believe is deprecated. The above is the preferred way.

Dan Breen
+1  A: 

There are a few ways to do this; none of them are the easy, obvious way.

Applying white-space:nowrap to a won't work; only four CSS properties work on elements - background-color, width, border, and visibility. IE7 and earlier used to support all properties, but that's because they used a strange table model. IE8 now matches everyone else.

So, how do you solve this?

Well, if you can ignore IE (including IE8), you can use the :nth-child() pseudoclass to select particular s from each row. You'd use td:nth-child(2) { white-space:nowrap; }. (This works for this example, but would break if you had any rowspans or colspans involved.)

If you have to support IE, then you've got to go the long way around and apply a class to every that you want to affect. It sucks, but thems the breaks.

In the long run, there are proposals to fix this lack in CSS, so that you can more easily apply styles to all the cells in a column. You'll be able to do something like td:nth-col(2) { white-space:nowrap; } and it would do what you want.

Xanthir