使用带有gatsbyJS的样式组件

Jia*_*Tan 0 css reactjs server-side-rendering gatsby styled-components

我正在使用gatsby-plugin-styled-components来设计下面的元素.

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;
Run Code Online (Sandbox Code Playgroud)

由于某些原因,我只是无法弄清楚自己,我无法设置secondChar组件的样式.颜色和字体大小根本不会改变.但是,我可以通过Chrome Dev Tool设置secondChar的样式.

任何人都可以建议发生了什么?谢谢.

更新:解决了上面的第一个问题.忘了使用camelcase作为组件.

现在我正在尝试实现以下 Styled组件:引用其他组件

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>
)
Run Code Online (Sandbox Code Playgroud)

但是,悬停在TitleWrapper上的SecondChar组件没有任何响应.我又做错了吗?

小智 6

所有组件命名都应以大写字母开头,包括样式组件,所以secondChar应该是SecondChar