开发者

String formatting with CSS

开发者 https://www.devze.com 2023-04-09 15:01 出处:网络
I have a string with multiple lines as below separated by multiple spaces (or sometimes with single space):

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;开发者_Python百科
    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).


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号