Prevent word wrap in a table cell

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi, all! I have a question.

I am designing a listing similar to a phone book in HTML. Each listing has
periods following it, but they must extend to the end of the table cell, and
not wrap.

Is there any way to prevent the text from 1) wrapping within the table cell
and 2) causing the table cell to expand? In other words, the filler periods
must flow past the right boundary of the cell (but not be seen). Similar to:

[Ben's Car Shop.......................] [555-5555]

Any information is appreciated. Thanks!


Re: Prevent word wrap in a table cell

Quoted text here. Click to load it

Within the <td> itself:
<td style="white-space: nowrap;">foo</td>

In a stylesheet, something like:

table td {white-space: nowrap;}

The above would apply to all <td>s.

-- /

Re: Prevent word wrap in a table cell

Quoted text here. Click to load it

The big problem here is how to implement the periods. Several approaches have
been suggested on such matters in c.i.w.a.stylesheets. Whether the whole idea
is feasible on the WWW is debatable. In any case, it would be more like a
styling issue than HTML. You don't really want to have masses of periods as
_content_ of your pages.

Quoted text here. Click to load it

In HTML, several ways:

a) <td>foo&nbsp;bar</td> (or with &nbsp; replaced by the no-break space

b) <td nowrap>foo bar</td> (suitable only if _all_ line breaks inside a cell
are to be suppressed)

c) <td><nobr>foo bar</nobr></td> (nonstandard but widely supported)

d) <td><pre>foo bar</pre></td> (has other effects as well, somewhat nastily)

In CSS, use white-space: nowrap.

Quoted text here. Click to load it

In HTML, no. The CSS side of the matter belongs to our sister group. It's not
trivial, but you could use table-layout: fixed for the table, set the cell
width, and set overflow: hidden for the cell. This would imply that essential
information will be made invisible to some users unless you are very careful.
You didn't think of setting the width in pixels, did you?

Quoted text here. Click to load it

Is this really about telephone numbers, or what?

The recommended (by ITU) notation for telephone numbers does not use hyphens
but spaces. You could use the no-break space character, which works well,
whereas the nonbreaking hyphen is poorly supported.

In the WWW context, phone numbers should be expressed in the international
notation (starting with "+"), unless limited to a single country or other
numbering area and clearly indicated as such.

(Telephone numbers could be made links, using the tel: scheme. This might be
nice in the future when (or if) browsers support tel: URLs and let the user
just click on a number to make a phone call or send a text message. Then
again, if it became common, spammers would try to make use of it.)

Yucca, /
Pages about Web authoring:

Site Timeline