如何使用CSS在HTML< code>中保留换行符。块? [英] How can I use CSS to preserve line breaks in an HTML <code> block?
本文介绍了如何使用CSS在HTML< code>中保留换行符。块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些代码示例,我想在一个HTML文档中发布。我将它们与< code>标签,但我希望它们的样式,使换行符保留。我可以做到这一点,也用< pre>标签,但我更喜欢使用CSS。
我试过下面的IE7(根据这个引用应该工作),但没有快乐(换行符被删除):
code {
white-space:pre;这是可能吗?}
h2_lin>解决方案检查你的doctype是否有效,在第一行。也许它正在滑入怪异模式?
I have some code samples which I want to publish in an HTML document. I'm wrapping them with <code> tags but I'd like them to be styled such that line breaks are preserved. I can do this by also enclosing them with <pre> tags but I'd prefer to use CSS.
I've tried the following in IE7 (which according to this reference should work) but with no joy (line breaks are stripped):
code {
white-space: pre;
}
Is this possible?
解决方案 Check your doctype is valid and on the first line. Maybe it's slipping into quirks mode?
这篇关于如何使用CSS在HTML< code>中保留换行符。块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文