Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何使用react样式化组件添加自定义css_Reactjs_Styled Components - Fatal编程技术网

Reactjs 如何使用react样式化组件添加自定义css

Reactjs 如何使用react样式化组件添加自定义css,reactjs,styled-components,Reactjs,Styled Components,我有一张卡片,我想使用react样式组件添加自定义css名称。请建议我如何完成下面的工作 <div className='card custom-css'> <span> test </span> </div> 试验 您可以通过以下方式完成 从需要设置样式的div中创建一个新组件- 例如: 试验 然后可以按如下方式设置此组件的样式- const Test = styled.div` color: blue; /* write you

我有一张卡片,我想使用react样式组件添加自定义css名称。请建议我如何完成下面的工作

<div className='card custom-css'>
  <span> test </span>
</div>

试验

您可以通过以下方式完成

  • 从需要设置样式的div中创建一个新组件- 例如:

    
    试验
    

  • 然后可以按如下方式设置此组件的样式-

    const Test = styled.div`
      color: blue; /* write your css here */
    `
    
    const Test = styled(Test)`
        div {
            font-weight: bold;
        }
        color: blue; /* css for the entire component */
    `
    
  • 在父组件样式中设置特定div的样式-例如:

    const Test=()=>(
    试验
    )

  • 并按如下方式设置组件的样式-

    const Test = styled(Test)`
        .card {
            font-weight: bold;
        }
        color: blue; /* css for the entire component */
    `
    
    此外,您还可以通过以下方式设置组件中所有div的特定样式-

    const Test = styled.div`
      color: blue; /* write your css here */
    `
    
    const Test = styled(Test)`
        div {
            font-weight: bold;
        }
        color: blue; /* css for the entire component */
    `
    

    参考此处获取文档-

    您可以在此处找到信息:您可以推荐任何使用样式化组件中的{css}的示例吗。我没有从给定的链接中找到