views:

751

answers:

6

I have some table cells containing dates formatted like this: 2009-01-01. I.E 7 seems to be breaking these into two lines at the hyphen. Is there any way to turn this off?

+1  A: 

You could give the table cell a width that's bigger than the width of the datestring.

Lex
+4  A: 

You could try nowrap.

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

or

<td nowrap>Hello - World</td>
Jonathan Sampson
+5  A: 

I'm sure there's a better CSS way but the old way is with a no-break: <nobr>...</nobr> but using no-break will cause nothing to go to the next line.

Another way is to use a Non-breaking hyphen. This way, you can still get wrapping, just not at the hyphen.

Dinah
Non-breaking hyphen is the way to go. +1
Borgar
+5  A: 

Use this CSS:

.nowrap {
    white-space: nowrap;
}

Wrap your dates like: <span class="nowrap">2009-01-01</span>.

Edit: the advantage of this solution over others is that it gives you more precise control over what should or should not wrap. Your cells may still wrap for spaces and other hyphens, outside the span.

eyelidlessness
+1  A: 

increase the size of your TD and it wont be a problem

Jimmy
+1  A: 

This is NOT the correct way of answering your question, but this is how I do it:

<td>Hello&nbsp;-&nbsp;World</td>

I like this method better because you do not need to add a <style> or class attribute. Also, it makes the text one string so that it cannot be line wrapped by the browser.

Like I said, most people would disagree, but I think this is where a practical solution is better than the standards solution.

Christopher Altman