【问题标题】:Styled-component is not getting apply to the component样式组件未应用于组件
【发布时间】:2018-12-12 14:17:42
【问题描述】:

这是我的组件,它没有应用样式,即。就我而言,背景是组件。

import React from 'react';
import styled from 'styled-components'

const TappableButton = (props) => {
  return(
  <div>
    <Button>{props.title}</Button>
  </div>)
}

const Button = styled.button`
  background: "red";
`;

export default TappableButton;

【问题讨论】:

  • 你在哪里应用了这种风格?
  • 我正在使用样式组件
  • @Justcode 实际上我刚才弄错了.. 将添加答案。

标签: reactjs styled-components


【解决方案1】:

我明白了.. 问题在于引号,它可以在没有引号的情况下使用,只是将“红色”更新为红色。

【讨论】:

    【解决方案2】:

    改变

    const Button = styled.button`
      background: "red";
    `;
    

    const Button = styled.button`
      background: red;
    `;
    

    您不需要在该文本周围加上引号。 demo

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 2019-02-14
      • 2021-03-27
      • 2021-12-14
      • 1970-01-01
      • 2023-03-29
      • 2021-03-24
      • 2019-10-18
      • 1970-01-01
      相关资源
      最近更新 更多