【问题标题】:How to Add Custom CSS and Script in AMP Pages如何在 AMP 页面中添加自定义 CSS 和脚本
【发布时间】:2019-04-25 22:05:50
【问题描述】:
    <!doctype html>
<html ⚡>
  <head>
    <meta charset="utf-8">
    <title>Sample document</title>
    <link rel="canonical" href="AMPstyle.html">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <style amp-custom>
   @import "css/style1.css"; 
  {% include "css/style2.css" %}
    </style> 

<script type="application/ld+json" src="../Scripts/appjs/StaticCampaigns.js"></script>
    <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "NewsArticle",
      "headline": "Article headline",
      "image": [
        "thumbnail1.jpg"
      ],
      "datePublished": "2015-02-05T08:00:00+08:00"
    }
    </script>
    <script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
    <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>
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
       <!-- <link rel="stylesheet" type="text/css" media="all" href="css/initcarousel.css" /> -->

  </head>
  <body>
<h>AMP Pages Example.</h>
</body>
</html>

我在添加 CSS 和脚本时收到无效的 AMP 页面。我无法添加样式表并且 CSS 不起作用。自定义 CSS 和脚本不起作用。请建议我如何在 AMP 页面中添加自定义 CSS (@import "css/style1.css";) 和 Script(src="../Scripts/appjs/StaticCampaigns.js")。

【问题讨论】:

    标签: html asp.net asp.net-mvc amp-html


    【解决方案1】:

    它对我有用,试试这个

    <style amp-custom>
            @import url('css/main.css');
    </style>
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    AMP 文档要求所有 CSS 都内联在页眉中,并要求您在样式标记上使用 amp-custom 属性。看起来您正试图在页眉中添加 @import 语句,即使这不是 AMP 也是无效的。我建议先编译它,然后将内容复制到样式标签中。请记住还有50,000 byte size limit

    例如:

    <style amp-custom>
      h1 {
       color: red
      }
    </style>
    

    至于脚本,您无法在 AMP 文档中包含编写的 JavaScript。您需要寻找等效的AMP component

    【讨论】:

      猜你喜欢
      • 2019-07-13
      • 1970-01-01
      • 2020-06-08
      • 2020-04-08
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      相关资源
      最近更新 更多