html - 包含 <style amp-boilerplate> 的原因是什么

标签 html css custom-attributes

我找到了以下 CSS boilerplate code需要使用 AMP。它有什么作用?

 <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

谁能知道在 AMP 页面中包含上述 css 代码的原因?

我可以写< style amp-boilerplate="amp-boilerplate">吗?而不是 < style amp-boilerplate> ?

最佳答案

Can anyone know the reason for including above css code in AMP pages ?

这段代码本身是为了隐藏页面,直到它完全呈现,然后淡入以提供更高的感知性能指标。如果您询问标签本身,<style amp-boilerplate> ,Google 在内部使用它来命令 DOM 和 CSSOM 的解析。

Can I write < style amp-boilerplate="amp-boilerplate"> instead of < style amp-boilerplate> ?

是的,您可以将标签名称作为标签的值,它仍然会通过 AMP 验证。但是,不建议这样做,因为 AMP 规范可能随时更改,并且这可能不再有效。

我已经通过在实时页面上使用 AMP 验证器工具以及在内部使用 NodeJS 验证器和 Python 验证器来确认这一点。

关于html - 包含 &lt;style amp-boilerplate> 的原因是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36517669/

相关文章:

c# - 字符串到 sqlsyntax

javascript - getElementsByName 返回未定义

html - 左右边距不相等,这是为什么

c# - 在类库中运行初始化代码是使用任何属性

javascript - 用于比较 2 个不同条件下的数字的 If...Else If 语句

javascript - 需要 Jquery 按钮鼠标悬停滚动到顶部

html - 链接的访问者选择器没有更改字体大小和其他属性,为什么?

css - 悬停时菜单消失,IE6错误?

javascript - 无法使用 JavaScript 将自定义属性添加到窗口对象

android - declare-stylable 名称如何链接到使用其属性的 View ?