Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Tables - How to make IE not break lines at hyphens

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?

like image 717
Greg Avatar asked Oct 14 '09 20:10

Greg


People also ask

How do you keep a hyphenated word together in HTML?

Use the word joiner character ( ⁠ ) around the hyphen.

How do you make text not break in HTML?

The <nobr> HTML element prevents the text it contains from automatically wrapping across multiple lines, potentially resulting in the user having to scroll horizontally to see the entire width of the text.

How do I wrap text in a table column in HTML?

There are two methods to wrap table cell <td> content using CSS which are given below: Using word-wrap property: This property is used to allow long words to break and wrap onto the next line. Using word-break property: This property is used to specify how to break the word when the word reached at end of the line.

How do you add a line break in HTML table?

The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems. The <br> tag is an empty tag which means that it has no end tag.


2 Answers

You are looking for the white-space property, which affords you control over how white space and line-breaks affect the content of your element. To collapse white space sequences, but prevent line-breaks, you can use the nowrap value:

.dates {
    white-space: nowrap;
}
<td class="dates">2009-01-01</td>
like image 144
Sampson Avatar answered Sep 19 '22 02:09

Sampson


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.

like image 22
Dinah Avatar answered Sep 21 '22 02:09

Dinah