Solution

To change body style of ant design card in react js, first install ant design library using npm install antd command import and use the Card component from it. You have to use style attribute with bodyStyle.

Snippet

In this snippet, see a small example of using the Card component of the Ant design library, with the use of title="Default size card" attribute. then use the style component bodyStyle={{ background: "lightpink", color: "#FFF" }}.

<Card
    title="Default size card"
    extra={<a href="#">More</a>}
    style={{
    width: 300
    }}
  bodyStyle={{ background: "lightpink", color: "#FFF" }}
>

Table of contents

  • Install Ant Design.
  • Import Ant Design Components..
  • Define the custom style.

Let’s start with the first step.

Step 1: Install Ant Design.

To get started, first you need to install Ant Design in your React project. So that you can run the following command in your terminal:

npm install antd

Step 2: Import Ant Design Components.

You need to import the Ant Design components that you want to use in your project. To create a card, you need to import the Card component from Ant Design. You can do this by adding the following code to your React component:

import { Card, Space } from "antd";

Step 3: Define the custom style.

This code creates a React for the Card component with styles for the body change the background to lightpink and color to white.

<Card
    title="Default size card"
    extra={<a href="#">More</a>}
    style={{
    width: 300
    }}
  bodyStyle={{ background: "lightpink", color: "#FFF" }}
>

Example

In this example, we will import the Card component from the ant library. We created a basic card using the Ant Design Card component in React JS. Inline css has to be used to change bodyStyle of ant design card.

Let’s start coding…

App.js

import { Card, Space } from "antd";
const App = () => (
  <Space direction="vertical" size={16}>
    <Card
      title="Default size card"
      extra={<a href="#">More</a>}
      style={{
        width: 300
      }}
      bodyStyle={{ background: "lightpink", color: "#FFF" }}
    >
      <p>Card content</p>
      <p>Card content</p>
      <p>
        With supporting text below as a natural lead-in to additional content.
      </p>
    </Card>
  </Space>
);
export default App;

Output

Ant-design, body-style, card

Here, we are provided code sandbox links for the above program to change body style of ant design card in react js. Then you can use whenever you went and do the changes as per your requirements

codesandbox

Happy Coding,

I hope the above example with help you to do your task.