question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I override an antd style?

See original GitHub issue

I’m not sure if it is a bug or not, but in antd 2.7.0, the modal footer style looks like this:

.ant-modal-footer {
  border-top: ...
  padding: 10px 18px 10px 10px;
  text-align: ...
  border-radius: ...
}

Why is the padding-right 18px and not 10px? This creates asymmetry.

I’m trying to import a less file to override it:

@import "../../node_modules/antd/lib/style/themes/default.less";

: global {
  .ant-modal-footer {
    padding: 10px 10px 10px 10px;
  }
}

But it gets overridden by the default style.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

60reactions
benjycuicommented, Sep 4, 2017

antd’s style:

.ant-btn { ... }

Your style:

.my-btn.ant-btn { ... }

Then, you can override it

27reactions
Loratadincommented, Oct 2, 2019

antd’s style:

.ant-btn { ... }

Your style:

.my-btn.ant-btn { ... }

Then, you can override it

Can you kindly show how to achive this in react components, i’m unable to override any antd styled component and it’s killing me

In your js file you wrap antd button inside your own parent tag (e.g. “saveButtonWrapper”):

  <div className="saveButtonWrapper">
      <Button icon="check-circle">Save</Button>
  </div>

In less file nest the .ant-… classes inside your own parent tag’s className (in order to avoid overriding all the antd classes in the whole app after code compilation). Write there your own css properties, for example:

.saveButtonWrapper {
      width: 120px;
      .ant-btn {
           width: 100%;
           background-color: @dark-navy;
           color: @white;
      }
      .ant-btn:hover,
      .ant-btn:focus,
      .ant-btn:active {
           border-color: @light-gray;
           background-color: @dark-gray;
           color: @white;
      }
      .anticon {
           color: @green,
           font-size: 16px;
           margin-right: 10px;
      }
}

If you still need more detailed explanation, please refer to the video I posted on YouTube on how to customize Ant Design components - tabs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Antd: How to override style of a single instance of a component
I'm using webpack to import the antd.less file in a global App.less file. Then I override some global styles and webpack bundles everthing:...
Read more >
Customize Theme - Ant Design
Themes with different styles can be quickly generated by modifying ... Similarly, other Design Token of components can also be overridden in this...
Read more >
Ant Design CSS Override Demo - CodeSandbox
Ant Design CSS Override Demo. 1. Embed Fork Create Sandbox Sign in. Sandbox Info ... button. index.js. styles.css. package.json. Dependencies. antd.
Read more >
How to use styled-components for AntD
styled-components is an npm library to help overwrite CSS styling. Note that AntD uses its own css classes to style its components. You...
Read more >
A baby guide to overriding AntDesign theme and color.
Step 5: On this path /node_module/antd/dist run this command lessc --js my-theme.less result.css or compile it inside the project style ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found