Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3685
  • Last Modified:

How to force text to wrap in a table cell?

So, I have a table with fixed layout.
I have a column that holds a long string that half of the time will not fit the column.
In Internet Explorer the string wraps nicely. In Firefox, the text just go straight stubbornly making the table look bad.
Now, if I wrap the text inside a "span" it behaves the same way in each browser.
If I wrap the text with a "p" tag, I can style the tag with the same width as the thead and the width is respected now. However, the text still does not wrap in Firefox. Adding "overflow:scroll;" to the "p" style makes the width respected in both browsers but it looks awful with the scroll bars.

How do I force this string to wrap?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD>
    <STYLE type="text/css">
      table { 
	  	table-layout:fixed;
      }
	  
	  .hostName
	  {
	  	width:100px;
		border:solid 1px green;
   	 }
	 
	 .hostRow
	 {
	 	width:100px;
		border:solid 2px brown;
	 }
	 
    </STYLE>
  </HEAD>
  <BODY>
 
	<table>
	    <tr>
		<th class="hostName">Host name</th>
		</tr>
	
		<tr>
		<td class="hostRow">
			232.166.205-77.rev.gaoland.net 
		</td>
		</tr>
		
		<tr>
		<td class="hostRow">
			c-68-41-143-155.hsd1.mi.comcast.net  
		</td>
		</tr>
	
	
	</table>
 
  </BODY>
</HTML>

Open in new window

0
fischermx
Asked:
fischermx
  • 5
  • 2
  • 2
  • +1
1 Solution
 
lpxtechCommented:
You can use the css property word-break: break-all;
0
 
fischermxAuthor Commented:
Nope, that doesn't work.
0
 
lpxtechCommented:
Sorry, I failed to mention that this solution works only in IE. I'm don't think there is a firefox implementation of this yet.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
scrathcyboyCommented:
You misunderstand tables.  They AUTOMATICALLY wrap text for you, they don't have to be micromanaged like DIV tableless layouts.  Remove ALL the styling of your tables above, especially the layout:fixed ; -- that is just asking for trouble.  When you put data into table cells, from whatever source, the table cells buffer in the browser to the "best fit" layout.  

You only have to specify a width=780  or whatever for the table, and if you need specific cells to be so wide and so high, state that too in the <TD width=xxx height=yyy>.   However, if you want the tables to correctly buffer the display in wrapping the long lines, the best way is to leave the TDs alone and just specify a fixed width for the table -- the browser will do all the work for you in the table proportions.
0
 
Mark StegglesWeb DeveloperCommented:
0
 
fischermxAuthor Commented:
scrathcyboy:
What are you talking about?
I need this table to be fixed layout, I need this column to specifically have that size.

Steggs:
Thanks for the javascript hint. I think there's no easy answer for this question.
0
 
scrathcyboyCommented:
"What are you talking about?"
I am trying to explain tables to you, are you listening?

"I need this table to be fixed layout, I need this column to specifically have that size."

If you have a table 800 width, with 4 cells 200 width, and you stuff more text into one cell than 200, it WILL wrap.  If you want to CHOP OFF the text going into any cell, then please don't use tables, they don't do it.

There is a REAL easy answer to this question if you re-read my comments above re how tables work.  And no, no one has EVER needed javascript to wrap the content of a table when you get tables out of DIVs.
0
 
fischermxAuthor Commented:
Explain me this again:

"If you have a table 800 width, with 4 cells 200 width, and you stuff more text into one cell than 200, it WILL wrap."

Then, why the in the sample I'm showing you it doesn't wrap?

Show me in my sample, what do I need to do, to let the table do its magic, according to you.
0
 
fischermxAuthor Commented:
Also, please understand than this is an example, the real table has more columns, and all were looking good, except of this table.

Also, please note, that IE DOES what I want. Just FF does not.
So, it is not about you teaching me about tables, really.
0
 
fischermxAuthor Commented:
Actually, you are the one who is not listening, or reading.

The issue I'm trying to solve here is why FF does not respect the specified column size I have in the style.

Then the fact issue about the text is being wrapped or not is really an additional issue.

0
 
Mark StegglesWeb DeveloperCommented:
@scrathcyboy : If you read the question, we are not talking about TEXT... we are talking about an UNBROKEN STRING.
 
The only solution is to break the string. Unfortunately the css property word-break: break-all; is not supported in all the browsers... so you have to use javascript.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now