Two Laptop Bag
The moose likes HTML, CSS and JavaScript and the fly likes Preserve word wrap and line breaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Preserve word wrap and line breaks" Watch "Preserve word wrap and line breaks" New topic

Preserve word wrap and line breaks

Tom Wake

Joined: Feb 10, 2008
Posts: 5
Hi, I don't know if anyone here can help me on this one,

Basically I've got a page reading in text from a database.

Now there are problems that I've been encountering with white space.
I've made a section in my CSS to combat this problem which is now fine in firefox. Internet Explorer seems to be the problem.

putting in -
word-wrap: break-word; preserves line breaks in the text being read in, however this option doesn't wrap the text to the cell it's being put in.

white-space: normal; wraps the text to the cell but doesn't preserve line breaks.

I can only seem to use one of these options at a time so I'm abit stuck for ideas really. Does anyone know anything about this or a fix for it?

[ February 10, 2008: Message edited by: Bear Bibeault ]
Tom Wake

Joined: Feb 10, 2008
Posts: 5
Oh I was just wondering why this had been edited? I'm new here and hope I'm complying with your rules.

Hope someone can help me!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63867

It'd be helpful if you could provide a code snippet that clearly shows the issues. Make it the smallest snippet that exhibits the problem and be sure to use UBB code tags to preserve formatting (read this for more information).

With regards to editing, your subject line was probably adjusted. I usually do this when it's excessively long, contains all uppercase, isn't clear or on topic, or has excessive punctuation.

You might also want to include the text snippet you're trying to display.

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Welcome to Javaranch.

Other than our naming policy and our most important rule (Be Nice) there really aren't any rules that you could have broken.
I may have been that the moderator who edited your post saw a way to tweak your question to improve its chances of being answered.

We've compiled a page of tips, here.

Good luck with your question.


[ February 10, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tom Wake

Joined: Feb 10, 2008
Posts: 5
Hi guys,

Thank you for your quick responses.

Basically my CSS class is -

The code that reads in from the database is -

The pre codes in the class are fine for firefox and include line breaks in the text being read in and wrap the text within the cell.

The break-all is for IE, break word includes line breaks but doesn't wrap the text. If I use break-word it wraps the text within the cell but doesn't include line breaks.

Also, using <pre> </pre> tags intead of my css class doesn't seem to wrap the text in either browser.

Any ideas?
[ February 11, 2008: Message edited by: Tom Wake ]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Replace the breaks in the database with the <br/> tag.

Tom Wake

Joined: Feb 10, 2008
Posts: 5
Hi Eric,

Thanks for the suggestion. I have the problem that users of the website are able to submit News articles to the database and I'm sure that not everyone will remember to use code in their articles.

Is there a way to automatically convert line breaks to the html code?
Christophe Porteneuve
Ranch Hand

Joined: Jan 28, 2008
Posts: 43
Sure: how about:


Christophe Porteneuve aka TDD
"They did not know it was impossible, so they did it." --Mark Twain
Pragmatic Guide to JavaScript:
Prototype and
Tom Wake

Joined: Feb 10, 2008
Posts: 5
Thanks very much will give this a try
I agree. Here's the link:
subject: Preserve word wrap and line breaks
It's not a secret anymore!