新行没有< br>标签 [英] new line without <br> tag

查看:86
本文介绍了新行没有< br>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写下这个html:

  lorem ipsum 
lorem ipsum
lorem ipsum

浏览器显示:

  lorem ipsumlorem ipsumlorem ipsum 

有没有办法看到这个:

  lorem ipsum 
lorem ipsum
lorem ipsum

而不使用< br> 标签,并且不使用textarea。

我需要这个,因为我的文字有100.000个短行,而且要写< br> 标签100.000次是耗时的。

解决方案

您可以使用 < pre> 标记以保持换行符

 < pre> 
lorem ipsum
lorem ipsum
lorem ipsum
< / pre>

pre 标签的默认样式为等宽字体字体,但可以被覆盖。



您可以使用 white-space:pre CSS属性。

 < div style =white-space:pre> 
lorem ipsum
lorem ipsum
lorem ipsum
< / div>

white-space ,但您应该参阅文档以选择最合适的一个。



请注意, pre 会将每一个换行符都对待,包括< pre> < div> 标签。如果你不想要他们,你需要做:

 < div style = ...> lorem ipsum 
lorem ipsum
...


Writing this html:

lorem ipsum
lorem ipsum
lorem ipsum

browser shows:

lorem ipsumlorem ipsumlorem ipsum

Is there a way to see this:

lorem ipsum
lorem ipsum
lorem ipsum

without using <br> tag at the end of each line, and without using textarea.

I need this because I have a text with 100.000 short lines, and it is time consuming to write <br> tag 100.000 times.

解决方案

You can use the <pre> tag to keep the line breaks.

<pre>
lorem ipsum
lorem ipsum
lorem ipsum
</pre>

The default style for pre tags is monospaced font, but that can be overriden.

You can achieve the same effect without any extra default formatting using the white-space: pre CSS property.

<div style="white-space: pre">
lorem ipsum
lorem ipsum
lorem ipsum
</div>

There are several other values for white-space, but you should refer to the documentation to choose the most fitting one.

Note that pre will treat every line break the same including the one following the <pre> or <div> tags. If you don't want them you will need to do:

<div style=...>lorem ipsum
lorem ipsum
...

这篇关于新行没有&lt; br&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆