6

我正在使用这个卡片组件,我想在它之上构建。更具体地说,我想内联更改标题的背景颜色。按照我的想法,它看起来像这样:

<Card title='Produção e reembolso' style={{
  ant-card-head: {
    backgroundColor: '#232323'
  }
}} >
  <div> R$ {productionAmount} </div>
</Card>

这不起作用,因为 React 认为 ant-card-head 是一个属性名称。有没有办法做到这一点,或者我必须使用/创建一个不同的组件?

编辑

渲染的 HTML 看起来像这样

<div class="ant-card ant-card-bordered">
  <div class="ant-card-head">
    <h3 class="ant-card-head-title">Produção e reembolso</h3>
  </div>
  <div class="ant-card-body">
    <div><!-- react-text: 150 --> R$ <!-- /react-text --></div>
  </div>
</div>
4

1 回答 1

1

如果您想拥有一个具有样式的通用对象并从那里获取内容,则必须单独声明并使用内容。

const AllStyles = {
  "ant-card-head": {
    backgroundColor: '#232323'
  },
  "another-thing": {
    backgroundColor: '#ff00aa'
  }
};
<Card title='Produção e reembolso' style={AllStyles["ant-card-head"]} >
<AnotherElem title='Produção e empréstimo' style={AllStyles["another-thing"]} >

如果您只想为此元素内联样式,请执行此操作

<Card title='Produção e reembolso' style={{
  backgroundColor: '#232323'
}} >
于 2017-06-28T15:43:01.393 回答