我读到“pre”标签会将所有空格和制表符折叠成一个空格,但对我来说不是这样。
为什么会这样?它取决于网络浏览器还是我应该做更多的事情?
最佳答案
The PRE element tells visual user agents that the enclosed text is "preformatted". When handling preformatted text, visual user agents:
- May leave white space intact.
- May render text with a fixed-pitch font.
- May disable automatic word wrap.
- Must not disable bidirectional processing
PRE 标签将在您输入时留下空白。目的仅此而已。如果您不使用 pre 标记,标准 HTML 将折叠您所写的空白。如果您对保留 空白而不是折叠 感兴趣,请使用 PRE。
这是一个 example在 JSFiddle 中。
这将保留空白:
<pre>
Spaces
and more
galore
</pre>
这将折叠空白区域:
<div>
All
together
now
</div>
关于html - pre 标签中的空格不会被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6992627/