How to change antd Table header color

20.4k Views Asked by At

I tried to target base classes as below which doesn't work.

.ant-table .ant-table-container .ant-table-content table thead.ant-table-thead {
  background-color: green !important;
}

Is there a working way to achieve this? enter image description here

Corresponding JSX:

<Table columns={columns} dataSource={dataSource} />

Antd Table Docs: https://ant.design/components/table/

3

There are 3 best solutions below

2
On

Background Color for Table Header is come from Table Cell. Try using below rule.

.ant-table-thead .ant-table-cell {
  background-color: green;
}
0
On

This works without !important

Antd default styles are highly specific. You need to target the element with more specificity to override default styles.

!important is not required with the below specificity.

.ant-table
  .ant-table-container
  .ant-table-content
  table
  thead.ant-table-thead
  .ant-table-cell {
  background-color: green;
}
0
On

use "!important"

  .ant-table-thead .ant-table-cell {
  background-color: green !important;
  }