我不明白 HTML 5。验证器说:
The marginwidth attribute on the iframe element is obsolete. Use CSS instead.
The marginheight attribute on the iframe element is obsolete. Use CSS instead.
但根据this accepted answer :
there is no way to set the marginheight, marginwidth and frameborder properties of an iframe in a style sheet.
为什么他们要我做一些不可能的事情?
要么将可行的东西放入规范中,要么提出一个真正的替代方案。他们似乎弃用了某些东西,而他们的替代方案不起作用。
我在这里错过了什么?
最佳答案
HTML5 规范确实描述了 how the marginheight and marginwidth attributes work.它说的是:
For each property in the table below, given a body element, the first attribute that exists maps to the pixel length property on the body element. If none of the attributes for a property are found, or if the value of the attribute that was found cannot be parsed successfully, then a default value of 8px is expected to be used for that property instead.
Property Source 'margin-top' body element's marginheight attribute The body element's container frame element's marginheight attribute body element's topmargin attribute 'margin-right' body element's marginwidth attribute The body element's container frame element's marginwidth attribute body element's rightmargin attribute 'margin-bottom' body element's marginheight attribute The body element's container frame element's marginheight attribute body element's bottommargin attribute 'margin-left' body element's marginwidth attribute The body element's container frame element's marginwidth attribute body element's leftmargin attribute
If the body element's Document's browsing context is a nested browsing context, and the browsing context container of that nested browsing context is a frame or iframe element, then the container frame element of the body element is that frame or iframe element. Otherwise, there is no container frame element.
因此,要达到同样的效果,您必须在包含页面的 body 元素上设置 CSS 边距值,而不是 iframe 元素的 CSS 边距值。
规范接着解释了为什么 marginwidth 和 marginheight 可能不支持(甚至不应该)在浏览器中:
Warning! The above requirements imply that a page can change the margins of another page (including one from another origin) using, for example, an iframe. This is potentially a security risk, as it might in some cases allow an attack to contrive a situation in which a page is rendered not as the author intended, possibly for the purposes of phishing or otherwise misleading the user.
关于css - 为什么 HTML5 不验证但也不提供替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25311231/