英文:
How do I override the styles in ant-design 5?
问题
I'm using React (create-react-app), ant design 5.3.0 and modular scss.
When using embedded components, their styles override mine, because the component creates a wrapper and my styles are hung from the upstream wrapper and the downstream element creates the ant design itself.
To override them in scss, I figured out that I need to declare an inline class inside my class which generates ant design. For example, for Typography it will form .ant-typography. There's one BUT: if you don't use modular scss (don't write to files like head.module.css), you're fine. And if you write in modular scss files, it doesn't override.
Head.module.scss
index.js importing module scss
what render index.js with module scss
index.js importing plain scss
what render index.js with plain scss
(sorry: i dont have enough reputation to post images yet because of novice contributor)
I think it has something to do with kebab-case notation. I tried changing the notation to camelCase in the model files, but that didn't help either. Can you tell me how to solve the issue?
英文:
I'm using React (create-react-app), ant design 5.3.0 and modular scss.
When using embedded components, their styles override mine, because the component creates a wrapper and my styles are hung from the upstream wrapper and the downstream element creates the ant design itself.
To override them in scss, I figured out that I need to declare an inline class inside my class which generates ant design. For example, for Typography it will form .ant-typography.
There's one BUT: if you don't use modular scss (don't write to files like head.module.css), you're fine. And if you write in modular scss files, it doesn't override.
Head.module.scss
index.js importing module scss what render index.js with module scss
index.js importing plain scss what render index.js with plain scss
(sorry: i dont have enough reputation to post images yet because of novice contributor)
I think it has something to do with kebab-case notation. I tried changing the notation to camelCase in the model files, but that didn't help either. Can you tell me how to solve the issue?
答案1
得分: 1
尝试使用以下方式:
:global(.className) {
// 设置 CSS 属性
}
在模块化的 SCSS 文件中,例如:
:global(.swiper-pagination) {
width: 100%;
}
检查页面以找到需要覆盖的类名。这里有一个关于 :global
的链接:
https://stackoverflow.com/questions/43613619/what-does-global-colon-global-do
英文:
Try using
:global(.className) {
// Set CSS Properties
}
in the modular scss file
For example:
:global(.swiper-pagination) {
width: 100%;
}
Inspect the page to find the classname you need to override.
Here's a link about ':global':
https://stackoverflow.com/questions/43613619/what-does-global-colon-global-do
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论