CSS line breaks

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

CSS line breaks

Post by JellyFish »

Hello all, I was curious to know if there is a way to NOT ignore line breaks in an element. As you all know HTML by default ignores line breaks(\n characters), but is there a way through CSS to specify that the element WILL break on the newline characters? For example:

HTML:

Code: Select all

 
<p class="prelines">
This text preserves newline characters and nothing else like 
    tabs or more then one   space characters.
</p>
 
CSS:

Code: Select all

 
.preline {
some-rule-that-preserves-newline-characters: value;
}
 
RESULT:
This text preserves newline characters and nothing else like
tabs or more then one space characters.
What I'm looking for is the some-rule-that-preserves-newline-characters rule. I know I could use the white-space property but I believe this preserves tabs and multiple space characters as well(which is not what I want).

Thanks for reading. I hope there's such a CSS property.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: CSS line breaks

Post by pickle »

You can use white-space:pre-line. That is, unless you plan on having your site usable by IE. :roll:

http://www.htmldog.com/reference/csspro ... ite-space/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply