简体   繁体   English

替代 <pre> 和/或<code> tags?</code>

[英]Replacement for <pre> and/or <code> tags?

It appears <pre> and <code> are ignored by IE8 and FF10. 看起来<pre><code>被IE8和FF10忽略。 What can I do to display preformatted text? 如何显示预先格式化的文本?

They are not ignored. 他们不被忽视。 The <code> element has nothing to do with preformatted text, but it by default sets the font to monospace. <code>元素与预格式化文本无关,但默认情况下将字体设置为等宽字体。 The <pre> element works universally. <pre>元素普遍适用。 But neither of these elements overrides the normal HTML rule that the < character followed by a letter starts a tag; 但是这些元素都不会覆盖正常的HTML规则,即<字符后跟字母开始标记; they are not defined to do so, and they do not actually do so in browsers. 他们没有定义这样做,他们实际上并没有在浏览器中这样做。 I suspect a misunderstanding of this is the background to your question. 我怀疑对此的误解是你问题的背景。

Thus, within these elements, as elsewhere, to display < as data, write &lt; 因此,在这些元素中,与其他地方一样,要显示< as data,write &lt; , and to display & as data, write &amp; ,以及显示&作为数据,写&amp; .

The <xmp> element is different. <xmp>元素是不同的。 Within it, no markup is recognized, ie all characters are shows as-is; 在其中,没有识别标记,即所有字符都按原样显示; the end tag </xmp> is recognized, of course. 当然,识别结束标记</xmp> Though this element was deprecated in HTML 3.2 and removed from later specs (though it is mentioned as obsolete in HTML5), it still seems to have support in all browsers. 虽然这个元素在HTML 3.2中被弃用并从后来的规范中删除(虽然它在HTML5中被提及为过时),但它似乎仍然支持所有浏览器。 There was also a very similar element, <listing> , for wide listings, but support to it has been dropped. 对于广泛的列表,还有一个非常相似的元素<listing> ,但对它的支持已被删除。

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

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