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

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18431
  • Last Modified:

How to force line break in table cell..

Hi Guys..
I have a tablecell witch is filled dynamically.. The cell can contain lets say 15 letters.
If one text is 16+ Letters my design gets screwed up.. How do i break the text in two lines even if its one  word???? What part of HTML 101 did i miss??
And no, i cant use arrays and so on.. this is MANY rows..

Please.. tired.. help..

  • 5
  • 3
2 Solutions
The <br> tag in the html will force a "hard" return

Another option is to apply the "word-wrap:break-word;" css property to your table cell.

<TD STYLE="word-wrap:break-word;">

ref: http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/wordwrap.asp
Depends on whether you're constraining it by no. letters or width in pixels or whatever.

If no. letters, then you say it will be filled dynamically - which language will you be using?  You can break it up Server Side in any language pretty easily by adding <br>s in there.

If width then it's tricky.  The: word-wrap:break-word mentioned above only works in IE.  You can use an attribute: table-layout:fixed with which you then have a choice:


overflow: scroll

Which'll add scrollbars to it to let you see it all.  Or:

overflow: hidden

Which'll show the first part of the word and hide the rest.

I'm pretty sure there's some nasty JavaScript out there which does the job, but it's messy and causes the page to keep reloading while it works itself out.  Best bet is to do it Server Side.
mattisflonesAuthor Commented:
Hi guys, thanx for the input..
I`ve tried STYLE="word-wrap:break-word;" on the TD`s, P`s, TR`s and DIV`s... Doesnt work...

The table is 100Px wide, i need the tablecell to adjust height according to rows of text inside each cell.

The overflow:hidden sounds like a solution, but how to apply??? it isnt a Style is it? And could you give me examples on how to apply the table-layout:fixed thingey??
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.

mattisflonesAuthor Commented:
Btw.. 500 on this one now...
mattisflonesAuthor Commented:
This is the code.. The table is extended by repeats outside it..

<table width="100" border="0" cellpadding="2" cellspacing="2">
                <td align="left" valign="top"> <div align="left"><font size="1" face="Times New Roman, Times, serif"><%= DoDateTime((Recordset1.Fields.Item("Doppdatert").Value), 2, 1030) %></font><br>
                    <a href="nyheter.asp?nid=<%=(Recordset1.Fields.Item("nid").Value)%>"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><%=left(Recordset1.Fields.Item("header").Value,35)%></font></a></div></td>
mattisflonesAuthor Commented:
Actually this one worked...

<td align="left" valign="top" width="100" STYLE="word-wrap:break-word;width:89;left:0">

89 instead of 100...

Thanks for your efforts guys!
A bit like so:


<style type="text/css">

table {
width: 200px

.scroller {
overflow: hidden;
text-align: left



<body bgcolor="#FFFFFF">

                <td><div class="scroller">Veryveryveryveryveryveryveryveryveryveryverylongword<br>
                    <a href="something.htm">quitequitequitequitelongword</a></div></td>
As I said before, "word-wrap:break-word;" will only work in IE, Versions 5.5 upwards, incidentally, so a great deal of your users won't see that and it'll screw it up big time for them.
mattisflonesAuthor Commented:
I know! Thanks.. Its only going to be used in IE 5.5+ anyway...
Ill try the hidden stuff too..

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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