HTML – Wrap Text in Table Cell

I try to create a table in a Joomla content page but i find that the text will expand the table if it is too long.

The following style can solve the problem.

<style type="text/css">
	td {
		white-space: pre-wrap; /* css-3 */
		white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
		white-space: -pre-wrap; /* Opera 4-6 */
		white-space: -o-pre-wrap; /* Opera 7 */
		word-wrap: break-word; /* Internet Explorer 5.5+ */
	}
</style>

 

The above style will wrap the text in all the <td> tags of a HTML table with style=”table-layout:fixed” as well as defined width in <td> tag.

Unfortunately, The doesn’t work well in Joomla because it will also override the <td> tags of the Joomla content page which leads to the distortion of the layout.

So i have to add the style in each <td> tags just like the below HTML table.

<table width="520" style="table-layout:fixed">
	<tr>
		<td valign="top" width="140">First Name:</td>
		<td valign="top" width="380" style="white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word">Ying Kit</td>
	</tr>
	<tr>
		<td valign="top" width="140">Last Name:</td>
		<td valign="top" width="380" style="white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word">Yuen</td>
	</tr>
</table>

 

Done =)

Reference: Peter Bromberg;s Unblog – FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX

Advertisements

20 thoughts on “HTML – Wrap Text in Table Cell”

  1. Hi,
    I am using af:table (adf component to create a table). I want to wrap text in column (the text populated from database and hence dynamic).

    I tried the same as you mentioned above however that didnt work for me.
    any help.

    Like

  2. Hello,
    My requirement: TD width is % based and not fixed. TD height if 20px and should increase by 20 whenever text wrap happens.
    Problem: Since the width is dynamic, the word-wrap: break-word doesnt work. If I use the table-layout:fixed, the height of the TD doesnt increase when the wrap happens.
    Please suggest a solution so that the height should increase to accomodate a newline when text wrap happens.

    Like

    1. could you add padding to the HTML element inside TD?

      I think there is no way to change a hardcoded height of a TD tag when a text wrap happens.

      I hope i didn’t mis-interpret your requirement, if i did, i hope you could post an example here so that i could try it by myself.

      Kit

      Like

  3. Hi am using Extreme components(ec) table. I want to wrap text in column (the text populated from database and hence dynamic).

    I tried your solution. but it didn’t work for me.. Can you help me please..

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s