Nago Posted November 3, 2005 Share Posted November 3, 2005 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 More sharing options...
MadPotato Posted November 3, 2005 Share Posted November 3, 2005 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 More sharing options...
zeehond Posted November 3, 2005 Share Posted November 3, 2005 It's not that difficult Put ur text in a div <div style="width:100px;overflow:hidden;white-space:nowrap;"> put your text here</div> the text wil stand there but u won't see it Link to comment Share on other sites More sharing options...
alijsh Posted November 3, 2005 Share Posted November 3, 2005 You can apply wordwrap by setting width property e.g. width:50% or 200px ,etc.also you can set height if you like. If the contents are longer than width or height or both then the scrollbars will appear. Link to comment Share on other sites More sharing options...
Nago Posted November 3, 2005 Author Share Posted November 3, 2005 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 More sharing options...
Guest Timo Posted November 10, 2005 Share Posted November 10, 2005 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?<{POST_SNAPBACK}> 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 More sharing options...
Paim Posted November 10, 2005 Share Posted November 10, 2005 Just a question, how are you going to come up with text that exceeds 500px with no whitespace? Link to comment Share on other sites More sharing options...
Champion_Munch Posted November 11, 2005 Share Posted November 11, 2005 I'm having a similar problem. Just a question, how are you going to come up with text that exceeds 500px with no whitespace? http://www.zoneforums.com/munch/main/fatname.htmlIt aint exactly easy to squish 500 words into one line. :)wiht regards Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now