<pre> 和 <code> HTML 标签有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16065677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:38:17  来源:igfitidea点击:

What is difference between <pre> and <code> HTML Tag?

htmlhtml4

提问by Parimal Raj

How does a <pre>HTML tag differs from <code>html tag.

如何做一个<pre>从HTML标记不同<code>的HTML标签。

I have checked on W3Schools page, it seems they are just the same.

我在 W3Schools 页面上查看过,看起来它们是一样的。

If there any major difference between them ?

它们之间是否有任何主要区别?

回答by gpojd

Don't go to w3schools. Check the w3c documentation for preand codeinstead.

不要去w3schools。请查看 w3c 文档以获取precode

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 元素告诉可视用户代理所包含的文本是“预先格式化的”。在处理预先格式化的文本时,可视化用户代理:

  • 可能会留下空白区域。
  • 可以使用固定间距字体呈现文本。
  • 可能会禁用自动换行。
  • 不得禁用双向处理。

CODE:

代码:

Designates a fragment of computer code.

指定计算机代码片段。

回答by Quentin

<pre>says "The whitespace in this element is important" (so new lines and spaces get rendered as new lines and spaces).

<pre>说“这个元素中的空格很重要”(所以新的行和空格被渲染为新的行和空格)。

<code>says "This is code".

<code>说“这是代码”。

They have nothing in common aside from being HTML elements.

除了是 HTML 元素之外,它们没有任何共同之处。

W3Schools page, it seems they are just the same

W3Schools 页面,看起来它们是一样的

W3Schools is often wrong, often out of date, and often teaches worst practises. If they claim the two elements do the same thing, then that is just another reason to avoid the site.

W3Schools 经常是错误的,经常是过时的,并且经常教导最坏的做法。如果他们声称这两个元素做同样的事情,那么这只是避免该网站的另一个原因。