Reputation: 13
What I mean is, is it possible to make a div that when you type stuff into a div, it automatically makes a new line for each new line in the code it detects? For example, I want this:
<div>
Hello, World!
How are you doing today?
</div>
which would return
Hello, World!
How are you doing today?
Which in reality requires a <br>
or something. I don't want to have to put millions of them to make simple lines. The code I put before really outputs this:
Hello, World! How are you doing today?
I want automatic new line judged on the code's enters. Is this possible?
Upvotes: 1
Views: 52
Reputation: 25810
Use the CSS white-space property.
<div style="white-space:pre">
Hello, World!
How are you doing today?
</div>
Note that this will preserve all white space, including multiple spaces (such as your indent). If you want to collapse white space but still use newline characters to indicate line breaking, you can use the pre-line
value, though this option is not supported in ie7 (if that matters to you).
See a live example: http://jsfiddle.net/vyme6xs8/1/
Upvotes: 4