• 0

Forcing linebreak in a table?


Question

Is there any way to force a line break in a table?

Problem is that, I have a forum, which on the site it is used for resides in an iframe because of this the table I am using have widths set for both the table and it's cells (<td>) thing is that if someone would type in a message which is very long, for example a spam message without any spaces or anything it will just go on and the table will be wider than the width I have set, I dont want any horizontal scrolling in that iframe :/

anyway to force linebreaks if a cells contents are too long?

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

So there is no way to set the break after a certain amount of pixels?

Right now all my browser in windows have the same font size but on my virtual ubuntu box (running the same resolution) all the text is larger and a lot fewer characters fit on one row...

Link to comment
Share on other sites

  • 0

It is not possible for php to know the number of pixels the text is going to take up on a users screen because there is no feedback of such information. The best you can hope for is to use regex or the above mentioned method to make sure individual words are not too long to the point where they stick out of the container.

Link to comment
Share on other sites

  • 0

i tried setting overflow to hidden... but it still just made the table longer :/

i tried using table-layout:fixed and the worked with the overflow, but then it ignored the cell widths i had set so didn't work very well either :/

Link to comment
Share on other sites

  • 0

i tried setting overflow to hidden... but it still just made the table longer :/

i tried using table-layout:fixed and the worked with the overflow, but then it ignored the cell widths i had set so didn't work very well either :/

You mean wider ? overflow: hidden should work. Do you have a link to the page you are working on ?

Link to comment
Share on other sites

  • 0

Go to gustavjohansson.kaggteknik.se and click forum in the menu all the rest is totally irrelevant anyway but you should view it in the iframe it's supposed to be in...

The thread called "Djklfvhlsdurih" (don't ask about the name :p not me at least) is a good example of why i need to do something about long words. Sure if someone just type with spaces there wont be a problem, but what if someone would post a long link :/ would screw up the entire threads layout :/

Link to comment
Share on other sites

  • 0

Like I mentioned earlier this can be done using regex on server side after the text is submitted or on client side before the text is submitted. But since js is not so reliable I would recommend server side.

preg_replace('/([^\s]{25})(?=[^\s])/m', '$1 ', $text);

where 25 is the max number of characters a word can have.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.