0

I have a string with multiple lines as below separated by multiple spaces (or sometimes with single space):

"word1   word2       word3   word4
 word5   word same6  word7   word8"

In my Javascript I am able to split using \n, but when I display the same in a CSS div, it ends up in a weird format:

"word1 word2 word3 word4 word5 word same6 word7 word8".

My CSS:

.block{
    color: #000;
    border: 1px solid #fff300;
    padding:8px;
    margin:4px;
    width:80%;
    display: block;
}

How can I format the string with CSS? The spacing is not uniform and there's no guarantee on the spacing between words (and a word can also have a single space).

1
  • 2
    is not clear what formatting you want can you show it? Commented Sep 29, 2011 at 15:55

2 Answers 2

4

in HTML white space is condensed unless the white-space style has been set to a different value.

You might want to add:

white-space: pre;
-or-
white-space: pre-wrap;
-or-
white-space: nowrap;

to get it formatted correctly.

Sign up to request clarification or add additional context in comments.

Comments

1

Use white-space: pre. That should do the trick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.