简体   繁体   English

<pre>标签含义和空白CSS属性

[英]<pre> tag meaning and the white-space CSS property

<pre> tag is commonly known as " pre formatted text". <pre>标记通常称为“ 格式化文本”。

There is also a white-space CSS property which enables pre -like behaviour for any tag. 还有一个white-space CSS属性使pre任何标签式的行为。 However on it's description page at W3Schools and at CSS3 specs page this behavior is described as a " pre serving space algorithm". 但是, 在W3Schools描述页面CSS3规范页面上,此行为被描述为“ 占空间算法”。 In the same spec there is only a single place in which 'white-space' is referenced as a preformatted text. 在同一规范中,只有一个地方将“空白”称为预格式化文本。

Is this nonsense or maybe <pre> was initially a shorthand for a "preserving space" tag? 这是废话还是<pre>最初是“保留空间”标签的简写?

What's the background of this tag? 这个标签的背景是什么? I'm not a professional HTML designer, I know what's the meaning of the both versions, but I don't know how it is referenced or was referenced by people. 我不是专业的HTML设计师,我知道两个版本的含义是什么,但我不知道人们如何引用或引用它。 Is naming it 'preserving space' is a correct technical term which no-one uses? 命名“保留空间”是一个没有人使用的正确技术术语吗?

Of the two links you gave, W3Schools is probably not the best place to go for a reliably accurate definition like this. 在您给出的两个链接中,W3Schools可能不是获得可靠准确的定义的最佳位置。

And while the MDN page that you linked to is a much better resource, it is not the official CSS3 spec that you think it is; 虽然您链接到的MDN页面是更好的资源,但您认为并不是官方的CSS3规范; you'll find the official spec at http://www.w3.org/TR/CSS2/text.html#propdef-white-space 您可以在http://www.w3.org/TR/CSS2/text.html#propdef-white-space找到官方规范

If you read the official spec, you'll find that the behaviour is not described using either of the phrases you mentioned in the question. 如果您阅读了官方规范,就会发现问题中没有提到任何短语来描述行为。 (The word 'preserved' does appear, but only in the context of newlines). (“保留”一词确实出现,但仅在换行符的上下文中出现)。

The <pre> tag itself predates CSS; <pre>标记本身早于CSS; it was in very early versions of HTML, and was defined in those as "Preformatted text", but from a CSS perspective there is no specific meaning to the letters pre , other than referring back to the behaviour of the original HTML element of that name. 它是在HTML的早期版本中定义的,但在这些语言中被定义为“ 格式化的文本”,但是从CSS的角度来看,除了回溯该名称原始HTML元素的行为外,对pre并无特殊含义。 。

Early W3C documents, such as Hypertext Markup Language - 2.0 (dating from 1995) all call the <pre> element Preformatted text . 早期的W3C文档,例如Hypertext Markup Language-2.0 (自1995年以来),都将<pre>元素称为Preformatted text
Although some files also refer to the fact that <pre> "preserves spaces", they do indicate that's a result of the preformatting, not the intended purpose of this element. 尽管某些文件还提到<pre> “保留空格”的事实,但它们确实表明这是预格式化的结果,而不是此元素的预期目的。
For instance, the HTML 3.2 Reference Specification says 例如, HTML 3.2参考规范

The PRE element can be used to include preformatted text. PRE元素可用于包含预格式化的文本。 User agents render this in a fixed pitch font, preserving spacing associated with white space characters such as space and newline characters. 用户代理以固定间距的字体呈现此字体,并保留与空白字符(如空格和换行符)关联的间距。

The PRE-tag was and is used to display text with whitespace preserved. PRE标签以前是并且用于显示保留空白的文本。 So text does not wrap, newlines are not ignored, spaces are not ignored. 因此,文本不会自动换行,不会忽略换行符,不会忽略空格。

It is however possible to undo this any way you like with CSS (or Javascript). 但是,可以使用CSS(或Javascript)以任何您喜欢的方式撤消此操作。

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

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