加速移动页面链接到css文件

问题描述 投票:7回答:4

我想链接到css文件:

<link href="/semanticui/semantic.css" rel="stylesheet" />

#development=1模式下打开chrome来测试我的放大器页面。我收到此错误:

The attribute 'href' in tag 'link rel=stylesheet for fonts' is set to the invalid value '/semanticui/semantic.css'.
css mobile amp-html
4个回答
14
投票

不允许使用外部样式表。使用内联样式以避免对css的额外请求。

更多信息,请访问:https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#stylesheets

作者可以使用文档头部中的单个<style amp-custom>标记向文档添加自定义样式。


8
投票

我正在使用php页面,所以我执行以下操作来添加我的自定义css页面,因此我可以将其分隔并包含在所有页面中,因此只需更改一次等。

<style amp-custom>
  <?php readfile( getcwd() . "/css/main.min.css"); ?>
</style>

1
投票

页面及其元素的任何样式都使用常见的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>

0
投票

你可以用这个:

<style amp-custom>
    <?php echo file_get_contents(STYLESHEETPATH.'/style.css'); ?>
</style>
© www.soinside.com 2019 - 2024. All rights reserved.