简体   繁体   English

如何制作空白:预包装; 证明文本?

[英]How to make white-space: pre-wrap; justify text?

I have text within pre tags styled like this:我在 pre 标签中的文本样式如下:

 <pre style="white-space: pre-wrap; font-family: Georgia, 'Times New Roman', Times, serif;">
        ${htmlText} 
 </pre>  

Justify text won't work within white-space: pre-wrap;对齐文本在white-space: pre-wrap; . . But if the text is not white-space: pre-wrap;但如果文本不是white-space: pre-wrap; , then the text white space is deleted. , 然后文本空白被删除。 I need the text white space to remain and still be able to justify text.我需要保留文本空白,并且仍然能够证明文本的合理性。

I've also tried white-space: pre;我也试过white-space: pre; with overflow-wrap: break-word .带有overflow-wrap: break-word This works, but it splits the words when wrapping text.这可行,但它会在换行文本时拆分单词。 I need justify to work without splitting/breaking words.我需要证明在不分裂/破坏单词的情况下工作。

How do you make text-align: justify;你如何使text-align: justify; work with white-space: pre-wrap;使用white-space: pre-wrap; ? Or how do you make white-space: pre;或者你如何制作white-space: pre; while wrapping text in a way that doesn't break words up?同时以不打断单词的方式包装文本?

white-space: pre-wrap; has no affect on text-align: justify;text-align: justify; here is an example这是一个例子

 .a { white-space: pre-wrap; text-align: justify; }
 <pre class="a"> <p>This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.</p> <p>This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph</p> <p>This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph.This is a paragraph</p> </pre>

It looks like there's no fix for this.看起来没有解决方法。 The closest thing I could do is set white-space: normal and give every p tag the css property text-indent: 30px;我能做的最接近的事情是设置white-space: normal并为每个 p 标签提供 css 属性text-indent: 30px; . .

This will justify text and will add an indent to the beginning of every paragraph.这将证明文本的合理性,并将在每个段落的开头添加一个缩进。 But it will also delete all whitespace more than one whitespace.但它也会删除所有空格多于一个空格。 This works for me for now because I was most interested in adding extra whitespace to the beginning of paragraphs.这对我现在有用,因为我最感兴趣的是在段落的开头添加额外的空格。

也许这行得通: display: inline-block;

Did you try this:你试过这个吗:

.a {
white-space: pre-line;
text-align: left;

} }

In my case, this did the work.就我而言,这完成了工作。 I could manage multiline text and text is justified left我可以管理多行文本并且文本左对齐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM