问题描述
/** @jsx jsx */
import { jsx,css } from '@emotion/core'
import styled from '@emotion/styled'
import { Link } from 'gatsby'
import React from 'react'
import { AntDesignOutlined } from '@ant-design/icons'
import { Layout,Typography } from 'antd'
const AntHeader = Layout.Header
const { Title } = Typography
type Props = {
siteTitle: string
}
const Header: React.FC<Props> = ({ siteTitle }) => (
<AntHeader>
<div>
<h1>
<Link to="/" css={LinkStyle}>
<AntDesignOutlined />
{` `}
{siteTitle}
</Link>
</h1>
<TitleStyled>Title</TitleStyled>
</div>
</AntHeader>
)
Header.defaultProps = {
siteTitle: ``,}
const TitleStyled = styled(Title)`
color: red;
`
const LinkStyle = css`
color: #fff;
`
export default Header
我已在以下Gatsby入门程序上进行了演示:https://github.com/yusugomori/gatsby-starter-antd-typescript-emotion
我无能为力地解决此问题。
解决方法
这实际上与React,Gatsby,Ant Design或Emotion没有任何关系,只是CSS的特殊性。选择器el.foo
的特异性比.foo
高,因此其样式将优先。有关更多详细信息,请参见How are the points in CSS specificity calculated。
您可能还会发现techniques for overriding styles outlined in the Ant documentation有用。此外,这里还有一些替代方法:How to customize Ant.design styles