使用样式组件与gatsbyJS
问题描述:
我使用gatsby-plugin-styled-components来设计下面的元素。使用样式组件与gatsbyJS
import React from 'react';
import styled from 'styled-components';
const secondChar = styled.span`
font-size: 3em;
color: azure;
`
const TitleWrapper = styled.div`
font-size: 3.5em;
font-weight: 100;
letter-spacing: 0.01em;
font-family: 'Covered By Your Grace', cursive;
`
const Title =() => (
<TitleWrapper>
<span>a</span>
<secondChar>b</secondChar>
<span>c</span>
<span>e</span>
<span>f</span>
<span>g</span>
<span>h</span>
</TitleWrapper>
)
export default Title;
由于某种原因,我简直不知道自己,我无法风格的secondChar组件。颜色和字体大小根本不会改变。 但是,我可以通过Chrome开发工具设计secondChar风格。
任何人都可以建议发生了什么? 谢谢。
更新: 解决了上述第一个问题。忘记将camelcase用于组件。
我正努力实现下列 Styled-components: refering to other components
const SecondChar = styled.span`
display: inline-block;
transform: translateX(20px);
transition: transform 500ms ease-in-out;
${TitleWrapper}:hover & {
color: azure;
}
`
const TitleWrapper = styled.div`
font-size: 3.5em;
font-weight: 100;
letter-spacing: 0.01em;
font-family: 'Covered By Your Grace', cursive;
`
const Title =() => (
<TitleWrapper>
<span>a</span>
<SecondChar>b</SecondChar>
<span>c</span>
<span>d</span>
<span>e</span>
<span>f</span>
<span>g</span>
</TitleWrapper>
)
然而上空盘旋TitleWrapper没有SecondChar组件上任何回应。我又做错了什么?
答
所有组件命名应以大写字母开头,包括样式化组件,因此secondChar
应该是SecondChar