Next.JS + AMP CSS

3 css reactjs react-native amp-html next.js

我在 Next.js 中使用 AMP 和 CSS 时遇到问题。在我的头部组件中,我有:

<Head>
    <style amp-custom>{`
        // CSS Here
    `}</style>
</Head>
Run Code Online (Sandbox Code Playgroud)

在 HTML 源代码中,它显示为<style amp-custom=""></style><style>(CSS Here)</style>

在控制台中我收到此错误:The mandatory attribute 'amp-custom' is missing in tag 'style amp-custom (transformed)'.

如何在 CSS 和 Next 上使用 AMPHTML 规则?我尝试过的所有其他方法(例如使用 @zeit/next-sass 从文件导入)都会导致 CSS 根本无法渲染。这是我发现的唯一有效版本。

Yub*_*bin 6

尝试这个:

<Head>
    <style
      amp-custom=""
      dangerouslySetInnerHTML={{
        __html: `
          amp-img {
            border: 1px solid black;
          }
        `,
      }}
    ></style>
</Head>
Run Code Online (Sandbox Code Playgroud)