目錄 搜尋
Attributes accesskey (attribute) class (attribute) contenteditable (attribute) contextmenu (attribute) data-* (attribute) dir (attribute) draggable (attribute) dropzone (attribute) Global attributes hidden (attribute) id (attribute) itemid (attribute) itemprop (attribute) itemref (attribute) itemscope (attribute) itemtype (attribute) lang (attribute) slot (attribute) spellcheck (attribute) style (attribute) tabindex (attribute) title (attribute) translate (attribute) Elements a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 head header hr html i iframe img input input type="button" input type="checkbox" input type="color" input type="date" input type="datetime"-local input type="email" input type="file" input type="hidden" input type="image" input type="month" input type="number" input type="password" input type="radio" input type="range" input type="reset" input type="search" input type="submit" input type="tel" input type="text" input type="time" input type="url" input type="week" ins kbd label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt rtc ruby s samp script section select slot small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr Miscellaneous Attributes Block-level elements CORS enabled image CORS settings attributes Element Inline elements Kinds of HTML content Link types Microdata Optimizing your pages for speculative parsing Preloading content Reference Supported media formats Using the application cache Obsolete acronym applet basefont big blink center command content dir element font frame frameset hgroup image input type="datetime" isindex keygen listing marquee nextid noframes plaintext strike tt xmp
文字

HTML <pre>元素表示预定义格式文本。在该元素中的文本通常按照原文件中的编排,以等宽字体的形式展现出来,文本中的空白符(比如空格和换行符)都会显示出来。(紧跟在 <pre> 开始标签后的换行符也会被省略)

内容类别

Flow content, palpable content.

允许的内容

Phrasing content.

标记遗漏

没有,起始和结束标签都是强制性的。

允许父母

任何接受  flow content 的元素。

允许ARIA角色

任何

DOM界面

HTMLPreElement

属性

这个元素只包含全局属性。

cols定义每行的最大字符数。这是一个非标准的属性,作用与width相同。要实现这样的效果,应该使用CSS。

width包含每行的最大字符数。虽然在技术上仍被实现,但这个属性没有视觉效果。要实现这样的效果,应该使用CSS。

wrap提示溢出怎样发生。在现代浏览器中,这个提示会被忽略,且被没有视觉效果。要实现这样的效果,应该使用CSS。

例子

<!-- Some example CSS code -->
<pre>
body {
  color:red;}
  </pre>

结果

body {
  color:red;}

规范

Specification

Status

Comment

HTML Living StandardThe definition of '<pre>' in that specification.

Living Standard

No significant change from HTML Living Standard

HTML5The definition of '<pre>' in that specification.

Recommendation

No significant change from HTML 4.01 Specification

HTML 4.01 SpecificationThe definition of '<dl>' in that specification.

Recommendation

Deprecated the cols attribute

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

1

(Yes)

(Yes)

(Yes)

cols

No

No

1 — 29

No

No

No

width

(Yes)1

(Yes)1

12

(Yes)1

(Yes)1

(Yes)1

wrap

?

No

1

?

?

?

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

1

(Yes)

(Yes)

(Yes)

cols

No

No

No

1 — 29

No

No

No

width

(Yes)1

(Yes)1

(Yes)1

12

(Yes)1

(Yes)1

(Yes)1

wrap

?

?

No

1

?

?

?

上一篇: 下一篇: