【发布时间】:2021-04-05 21:52:27
【问题描述】:
我正在使用来自 gatsby-plugin-image 的 StaticImage 和 twin.macro 进行 CSS 样式设置,并遵循本指南:https://github.com/ben-rogerson/twin.examples/tree/master/gatsby-styled-components#getting-started
...
import tw, { css, styled, theme } from 'twin.macro'
import { StaticImage } from 'gatsby-plugin-image'
...
<StaticImage
imgStyle={tw`rounded-lg shadow-2xl`}
style={tw`p-4`}
src="../images/image.jpeg"
width={300}
quality={95}
formats={['AUTO', 'WEBP', 'AVIF']}
alt="Description"
/>
使用“imgStyle”设置内部 img 元素的样式适用于 twin.macro。但是,对 StaticImage 的 style 属性应用相同的技术会导致以下错误:
不应在 style={...} 属性中添加样式
如何将 twin.macro 应用于 StaticImage 的样式属性?
【问题讨论】:
-
你确定
StaticImage有style属性吗?... -
是的,至少文档中提到了:gatsbyjs.com/docs/reference/built-in-components/… style: CSSProperties 描述:应用于外包装的内联样式。