我正在尝试链接到 css 文件:
<link href="/semanticui/semantic.css" rel="stylesheet" />
在模式下打开 chrome#development=1
以测试我的页面是否有 amp。我收到此错误:
The attribute 'href' in tag 'link rel=stylesheet for fonts' is set to the invalid value '/semanticui/semantic.css'.
不允许使用外部样式表。使用内联样式来避免对 css 的额外请求。
可以在以下位置找到更多信息: https ://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#stylesheets
<style amp-custom>
作者可以使用文档头部的单个标签将自定义样式添加到文档中。
我正在使用 php 页面,所以我执行以下操作来添加我的自定义 css 页面,这样我就可以将它分开并包含在所有页面中,因此只更改一次等。
<style amp-custom>
<?php readfile( getcwd() . "/css/main.min.css"); ?>
</style>
页面及其元素的任何样式都是使用通用 CSS 属性完成的。在 中的内联样式表中使用类或元素选择器来样式元素,称为<style amp-custom>
这是示例代码:
<style amp-custom>
/* any custom style goes here */
body {
background-color: white;
}
amp-img {
background-color: gray;
border: 1px solid black;
}
</style>
你可以使用这个:
<style amp-custom>
<?php echo file_get_contents(STYLESHEETPATH.'/style.css'); ?>
</style>