简体   繁体   English

单独回车的CSS空白预包装规则

[英]CSS white-space pre-wrap rules for lone carriage return

Is it valid to put lone carriage-return characters into a HTML block formatted with white-space: pre-wrap ? 将单独的回车字符放入以white-space: pre-wrap分隔的HTML块是否有效white-space: pre-wrap

I've got an application which is receiving a SOAP message, and logging the message to a file. 我有一个正在接收SOAP消息并将消息记录到文件的应用程序。 Our logging code has always stripped new-line characters so on Unix, this is a one-line log entry. 我们的日志记录代码总是剥离换行符,因此在Unix上,这是一个单行日志条目。 The incoming message is windows format CRLF though, so after stripping the new-line, I'm left with lone carriage returns. 输入的消息虽然是Windows格式CRLF,所以在删除换行符之后,我剩下的是单独的回车符。

The log viewer screen on the application shows a table with the log entries having white-space: pre-wrap formatting. 应用程序上的日志查看器屏幕显示一个表,其中的日志条目具有white-space: pre-wrap格式。 On my browser at least, this looks great, with lone carriage returns working just the same as a new-line or CRLF. 至少在我的浏览器上,这看起来不错,单独的回车符与换行符或CRLF一样。

Is this reliable behaviour? 这是可靠的行为吗?

Yeah, it's valid. 是的,这是有效的。 Using white-space: pre-wrap; 使用white-space: pre-wrap; is exactly the same as using <pre> , except that it will naturally wrap lines according to the boundaries of its parent. <pre>完全相同,只是它会根据其父级的边界自然地换行。

However, you should consider making sure your CSS is cross-browser compliant. 但是,您应该考虑确保CSS与跨浏览器兼容。

#log {
    white-space: pre-wrap;       /* CSS3 */
    white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
    white-space: -pre-wrap;      /* Opera 4-6 */
    white-space: -o-pre-wrap;    /* Opera 7 */
    word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

You can also use white-space: pre; 您还可以使用white-space: pre; if you want line to push the boundaries of its parent to keep everything in the output on a single line 如果您想使行超出其父级的边界,以使输出中的所有内容都在一行上

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

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