目录搜索
Attributesaccesskey (attribute)class (attribute)contenteditable (attribute)contextmenu (attribute)data-* (attribute)dir (attribute)draggable (attribute)dropzone (attribute)Global attributeshidden (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)Elementsaabbraddressareaarticleasideaudiobbasebdibdoblockquotebodybrbuttoncanvascaptioncitecodecolcolgroupdatadatalistdddeldetailsdfndialogdivdldtemembedfieldsetfigcaptionfigurefooterformh1headheaderhrhtmliiframeimginputinput type="button"input type="checkbox"input type="color"input type="date"input type="datetime"-localinput 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"inskbdlabellegendlilinkmainmapmarkmenumenuitemmetameternavnoscriptobjectoloptgroupoptionoutputpparampicturepreprogressqrprtrtcrubyssampscriptsectionselectslotsmallsourcespanstrongstylesubsummarysuptabletbodytdtemplatetextareatfootththeadtimetitletrtrackuulvarvideowbrMiscellaneousAttributesBlock-level elementsCORS enabled imageCORS settings attributesElementInline elementsKinds of HTML contentLink typesMicrodataOptimizing your pages for speculative parsingPreloading contentReferenceSupported media formatsUsing the application cacheObsoleteacronymappletbasefontbigblinkcentercommandcontentdirelementfontframeframesethgroupimageinput type="datetime"isindexkeygenlistingmarqueenextidnoframesplaintextstrikettxmp
文字

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

?

?

?

上一篇:下一篇: