2017-06-13 42 views
0

通過添加樣式屬性,我只能更改卡組件正文部分的顏色。我怎樣才能改變標題部分?Antd - 無論如何改變卡片標題的背景顏色?

<Card title='Card title' bordered loading={this.onLoading()} 
    style={{ backgroundColor: '#aaaaaa' }}> 
    <Row type='flex' justify='center'> 
    <h1>Card content</h1> 
    </Row> 
</Card> 

enter image description here

回答

1

你有一些錯字。 style:{{backgroundColor:'#aaaaaa'}}應該style={{ backgroundColor: '#aaaaaa' }}和它的作品對我來說:

enter image description here


使用相同的代碼和它的工作:

enter image description here

enter image description here

我可能需要檢查你的網頁知道爲什麼它不適合你

+0

感謝您的快速響應。它仍然不適合我。我編輯了這篇文章並添加了一個例子。 –

+0

完全相同的代碼,它爲我工作..你可以檢查標題的風格? – CodinCat

+0

順便說一下,你是否使用'antd'來產生結果,即'從'antd'導入{Card} –

1

最後,我沒有選擇,並使用CSS來解決這個問題。 antd卡的結構類似於

<div class="ant-card ant-card-bordered"> 
    <div class="ant-card-head" \> 
    <div class="ant-card-body" \> 

和.ant-card-head的背景風格爲#fff。

如果我確實喜歡<Card style={{background:"#aaa"}},它將覆蓋.ant-card類。如果我做的是<Card bodyStyle={{background:"#aaa"}},它將覆蓋.ant-card-body類,我找不到任何直接覆蓋.ant-card-head類的方法,所以我最終使用css來設置.ant-card-身體背景到無和它的作品。