If you already know how to disable word-wrapping within a table's cell, you can skip this lesson.
Normally,when the browser encounters lots of text within a cell, it adjusts the size of the cell as wide as possible to accommodate the entire text. If the cell size or table width has been specified explicitly, it word-wraps the text inside the cell, to keep the width constant, and makes the cell taller as required to accommodate the text. Sometimes, you might not want the cell made taller, but you don't mind it being made wider. By turning OFF word-wrapping within the cell, the cell will then be made as wide as it needs to be to accommodate the text (even beyond the width of the screen).
To turn OFF word-wrapping within a cell, use one of these formats, as appropriate:
<TD NOWRAP> (for table-data cells)
or
<TH NOWRAP> (for table-heading cells)
The 'NOWRAP' attribute does not take a value; its mere presence in the opening tag for the cell indicates that word-wrapping should be turned off.
Now let's see some examples demonstrated:
<TABLE BORDER=5> <TR><TH>Ditty No 1</TH> <TD>The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you)</TD></TR> <TR><TH>Ditty No 2</TH> <TD>Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place?</TD></TR> </TABLE> <P> Here's the same table with width set at 50% of screen (word-wrapping ON by default): <P> <TABLE BORDER=5 WIDTH=50%> <TR><TH>Ditty No 1</TH> <TD>The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you)</TD></TR> <TR><TH>Ditty No 2</TH> <TD>Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place?</TD></TR> </TABLE> <P> Here's a table with word-wrapping turned OFF in all the cells: <P> <TABLE BORDER=5> <TR><TH NOWRAP>Ditty No 1</TH> <TD NOWRAP>The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you)</TD></TR> <TR><TH NOWRAP>Ditty No 2</TH> <TD NOWRAP>Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place?</TD></TR> </TABLE> <P> Here's a table with word-wrapping turned OFF and all the cells in one row: <P> <TABLE BORDER=5> <TR><TH NOWRAP>Ditty No 1 and Ditty No 2</TH> <TD NOWRAP>The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you)</TD> <TD NOWRAP>Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place?</TD></TR> </TABLE> <P> Here's a reasonable use of word-wrapping: <P> <TABLE BORDER=5 WIDTH=50%> <TR><TH NOWRAP>Ditty No 1</TH> <TD>The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you)</TD></TR> <TR><TH NOWRAP>Ditty No 2</TH> <TD>Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place?</TD></TR> </TABLE>
Here's a table with default settings (word-wrapping ON by default):
Ditty No 1 | The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you) |
---|---|
Ditty No 2 | Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place? |
Here's the same table with width set at 50% of screen (word-wrapping ON by default):
Ditty No 1 | The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you) |
---|---|
Ditty No 2 | Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place? |
Here's a table with word-wrapping turned OFF in all the cells:
Ditty No 1 | The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you) |
---|---|
Ditty No 2 | Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place? |
Here's a table with word-wrapping turned OFF and all the cells in one row:
Ditty No 1 and Ditty No 2 | The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you) | Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place? |
---|
Here's a reasonable use of the 'NOWRAP' attribute:
Ditty No 1 | The quick brown fox jumps over the lazy dog about a hundred million times before the canine snaps his wise-acre head right off (messy, very messy... not a pretty sight, I assure you) |
---|---|
Ditty No 2 | Peter Piper picked a peck of pickled peppers; how many pecks of pickled peppers did Peter Piper pick? And more importantly, what motivated this compulsion in the first place? |
Let's look at the tables we demonstrated and see how they behaved: