【发布时间】:2020-09-21 10:06:50
【问题描述】:
我正在与 Gatsby 一起使用 styled-components。我使用 styled-components 为 Gatsby 为我的主页提供的 Link 组件设置样式。
const HomePageLink = styled(Link)`
display: inline-block;
font-size: ${fontSizes.xxlarge};
text-decoration: none;
box-shadow: none;
:link,
:visited {
color: ${colors.slate};
}
:hover,
:active {
color: ${colors.red};
}
`
但是我意识到我还需要使用完全相同的样式设置纯 html <a /> 标签的样式。我想知道有没有办法让上面的样式组件适应<a />标签,而无需像这样复制代码
const HomePageAnchorTag = styled.a`
display: inline-block;
font-size: ${fontSizes.xxlarge};
text-decoration: none;
box-shadow: none;
:link,
:visited {
color: ${colors.slate};
}
:hover,
:active {
color: ${colors.red};
}
`
【问题讨论】:
标签: javascript css reactjs gatsby styled-components