13

I prefer create project style and components style with tailwind css framework. I want to use a few ant design component. Tailwindcss and ant.design have problems together. Ant design alignment loses when we import @import 'tailwindcss/base' to the project and when we delete it ant design alignment will work fine. ant design modify global styles and according of document I try to prevent this but not work this method for me! My babel.config.js:

['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],

I add this plugin to my webpack config:

new webpack.NormalModuleReplacementPlugin(
  /node_modules\/antd\/lib\/style\/index\.less/,
  path.resolve(__dirname, './src/antd.less'),
),

and antd.less file:

#antd {
  @import '~antd/es/style/core/index.less';
  @import '~antd/es/style/themes/default.less';
}
Masih Jahangiri
  • 9,489
  • 3
  • 45
  • 51

3 Answers3

14

I would recommend overriding some of Tailwind's base styles that are causing problems with Ant Design. For me, Ant Design icons did not have the correct vertical alignment when including Tailwind, so I replaced their default svg style in my global css file.

@tailwind base;

/* Override base SVG style to work with Ant Design */
svg {
  vertical-align: initial;
}
TripleJ
  • 141
  • 1
  • 3
  • 1
    @DaniloKörber Hi! do you mange to integrate those two? I'm having problem on some ant components like Skeleton and the tooltip – khierl Nov 22 '20 at 20:07
13

TailwindCSS applies certain base styles to smoothen the cross-browser experience.

Since you are also using Ant Design, which applies some base styles of its own, setting preflight to false in your tailwind config should work:

module.exports = {
  corePlugins: {
    preflight: false,
  }
}
Arun_Venkata
  • 131
  • 2
  • 4
0
    module.exports = {
          content: [
            "./src/**/*. 
        {js,jsx,ts,tsx}",
           ],
          theme: {
             extend: {},
          },
          plugins: [
             // ...
          ],
          corePlugins: {
               preflight: false 
                 // <== disable 
           this!
           },
        }
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '23 at 11:35