前置标记中的空格不会被忽略
我读过“pre”标签会将所有空格和制表符折叠成一个空格,但它不适合我。
为什么会这样呢?这取决于网络浏览器还是我应该做更多的事情?
I have read that the 'pre' tag will collapse all white spaces and tabs into one space, but it doesn't do so for me.
why is it so? is it depending on web browser or should I do something more?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 HTML 4.01 规范
PRE 标签将在您键入时留下空白。目的仅此而已。如果您不使用 pre 标记,标准 HTML 将折叠您所编写的空白。如果您有兴趣保留空白,而不是折叠它,请使用 PRE。
这是 JSFiddle 中的示例。
这将保留空白:
这将折叠空白:
From HTML 4.01 Specification
PRE tags will leave white space as you have typed it. The purpose is just that. If you don't use a pre tag, standard HTML will collapse white space as you have written. Use PRE if you are interested in preserving white space, not collapsing it.
Here is an example in JSFiddle.
This will preserve white space:
This will collapse white space:
PRE 标签只会让您的内容保持与您编写的格式相同的格式。
它用于保持“预格式化”文本与您编写的文本相同。
The PRE tag will just keep you contents in the same format as you wrote it.
it is used to keep your "preformatted" text the same way as you wrote it.