为什么 iframe 默认是内联元素?
Why are iframes inline-elements by default?
iframe = 内联?
今天调试一些布局问题时,我惊讶地发现 <iframe>
元素的默认显示 属性 为 inline
。
对我来说,这似乎很奇怪,尤其是考虑到您可以将 height
和 width
应用于浏览器尊重的 <iframe>
,而对于一个简单的内联元素。
谁能给我解释一下这背后的原因?
演示
HTML
<iframe id="test"></iframe>
CSS
alert($('#test').css('display'))
https://jsfiddle.net/0tdLr9pq/
谢谢!
IFRAME 代表内联框架。看到这个:http://www.w3.org/TR/html401/present/frames.html#h-16.5
因为 HTML4 规范是这样说的:
The IFRAME
element allows authors to insert a frame within a
block of text. Inserting an inline frame within a section of text is
much like inserting an object via the OBJECT
element: they both
allow you to insert an HTML document in the middle of another, they
may both be aligned with surrounding text, etc.
“与周围文本对齐[=29=]”部分表示默认情况下它们不应该是块级的。
确实,内联元素通常会忽略 height
和 width
属性:
10.3.1 Inline, non-replaced elements
The width
property does not apply.
10.6.1 Inline, non-replaced elements
The height
property does not apply.
iframe = 内联?
今天调试一些布局问题时,我惊讶地发现 <iframe>
元素的默认显示 属性 为 inline
。
对我来说,这似乎很奇怪,尤其是考虑到您可以将 height
和 width
应用于浏览器尊重的 <iframe>
,而对于一个简单的内联元素。
谁能给我解释一下这背后的原因?
演示
HTML
<iframe id="test"></iframe>
CSS
alert($('#test').css('display'))
https://jsfiddle.net/0tdLr9pq/
谢谢!
IFRAME 代表内联框架。看到这个:http://www.w3.org/TR/html401/present/frames.html#h-16.5
因为 HTML4 规范是这样说的:
The
IFRAME
element allows authors to insert a frame within a block of text. Inserting an inline frame within a section of text is much like inserting an object via theOBJECT
element: they both allow you to insert an HTML document in the middle of another, they may both be aligned with surrounding text, etc.
“与周围文本对齐[=29=]”部分表示默认情况下它们不应该是块级的。
确实,内联元素通常会忽略 height
和 width
属性:
10.3.1 Inline, non-replaced elements
The
width
property does not apply.10.6.1 Inline, non-replaced elements
The
height
property does not apply.