Jump to content

Forced Wrapping of Text


Nago

Recommended Posts

Is it possible to set an attribute for a div element so that if the text inside of it has a string that is so long (without <br> or whitespace) that it will "break" the line to prevent it from displaying outside of the div? as it stands, if a line entered is too long or is contained within a <pre> tag, it goes right outside of the defined border area.If a concrete example of the page is needed, I'll send the link in a private message so you can look at the problem that is occurring and the circumstances in which I'd like to fix it.Any alternative solutions are welcome, but I'd like to avoid scripting if possible.Thanks for the help, -Nago

Link to comment
Share on other sites

well...i dont know if its possible to do it withou scripting, and probably only a server-side script should be able to solve the problemsomething verifying the length of the text, and inserting whitespaces after a defined number of chars...

Link to comment
Share on other sites

Overflow hidden will, as I understand, actually mask the excess text- the text that is "overflowing" is important and needs to be shown, but I would have liked to do it with a forced linebreak.The div element that this text is in already has a defined width- the problem is that if a string does not have whitespace in it and exceeds a certain amount of chars, it flows over the alotted border. In a short example, say this div is roughly 500px wide. If I have a word with no whitespace that now exceeds 500px, it extends PAST the border. I would manually add linebreaks for scenarios like this, but the content within this div is Automatically generated, and I don't have ways of easily modifying or controlling it.Otherwise, standard word wrap works fine. It breaks things that are too long and puts them on the next line. It's strings without whitespace that are the current problem.MadPotato: Do you have any suggestions, or otherwise a FAQ on how to accomplish an effect of that sorts?

Link to comment
Share on other sites

Overflow hidden will, as I understand, actually mask the excess text- the text that is "overflowing" is important and needs to be shown, but I would have liked to do it with a forced linebreak.The div element that this text is in already has a defined width- the problem is that if a string does not have whitespace in it and exceeds a certain amount of chars, it flows over the alotted border. In a short example, say this div is roughly 500px wide. If I have a word with no whitespace that now exceeds 500px, it extends PAST the border. I would manually add linebreaks for scenarios like this, but the content within this div is Automatically generated, and I don't have ways of easily modifying or controlling it.Otherwise, standard word wrap works fine. It breaks things that are too long and puts them on the next line. It's strings without whitespace that are the current problem.MadPotato: Do you have any suggestions, or otherwise a FAQ on how to accomplish an effect of that sorts?

I've had the same problem. I tried everything to let the layout (clientside) break the words, also tried overflow: hidden etc etc. I wasn't able to solve the problem. Then I tried it serverside, with more success. I solved it using PHP's wordwrap ():wordwrap ($string, 17, "<br />\n", 1)you should also specify this in your CSS:white-space: nowrap;Maybe it's useful to your situation.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...