-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global CSS included with component CSS import #4331
Comments
Do you mean CSS rules like this? html,
body {
...
} |
Yes. |
It's impossible not to import those CSS rules now. |
You have to override these global styles now. Or you drop the
|
That's terrible design though. |
This issue makes this library very difficult to work with. Especially having global properties on body etc. I think this issue should be made much more clear unless you have plans to change this. |
@forestDev @peitalin it's an known issue, but we don't have enough time to solve this issue. But we can keep discussing here. |
If we can import breaking changes, we can solve this issue. Such as, move styles in reset to components' styles: Move: * {
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove tap highlight color for mobile safari
} To: .ant-btn,
.ant-btn * {
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); // remove tap highlight color for mobile safari
} And for backward compatibility, we can provide a standalone reset stylesheet. import 'antd/styles/reset.less' |
is there any update on this? |
We can discuss, but we have no time to apply any solution(if we can find) now. |
I think this is a critical issue as not many people can afford importing a global css and having their existing styles overridden |
That is really annoying which stopped me from adopting Antd |
This will block many developers# |
because ant can not compatible bootstarp,i had to give up using ant. |
how about put out of less file into an independent library. btw. I am trying |
Related discussion: palantir/blueprint#244 |
Hey guys, I am working on antd@3.0 and try to find a solution for global styles issue. I tried the solution of Then I find the main point of this issue is about import Button from 'antd/lib/button';
import 'antd/lib/button/style/css'; // It will import reset styles and hard to override it because it was imported lately!!! The better workaround for this is not using @import '~antd/dist/antd.css';
// your global styles
body {
...
} So I give up the whole ant-design/components/style/core/base.less Lines 33 to 50 in afce275
Also I added better typography code from bootstrap@v4 to resolve #6162 All updates are in #7682 now and will be merged into antd-3.0 soon. |
@paneq I've copied what you've done and it seems to be worked so far, but I haven't tried enough components to see which ones require that global css. Thanks |
Add explantion in docs (customize theme) to how to prevent global styles pollution by configuring webpabk. Based on #4331 (comment)
hi, it should be possible to try match all elems, starting with .ant, and assign them styles *[class^='ant-']{ It should have crossbrowser compatibility and shouldn't take long to implement. |
Which version of less-loader are you using? Seems like it only works with 3.0.0? See. e.g. webpack-contrib/less-loader#184 Also, which version of antd were you using for this workaround? The reason I'm asking is that I didn't have success even with antd@3.7.3 and less-loader@3.0.0 (webpack had problems resolving after the change). .. |
I don't know if this helps anyone, but the following helped me import the CSS for only the component in use:
|
Yeah, this seems to work ok for many components. Your milage may vary, though -- at least Select needs a little more than just the component's own styles. The "remove" icon in selections won't render otherwise; I didn't have time to track down the issue completely, but i's probably something minor. So you may need to mimic some styles from the main styles in some of the components. While this option is not quite perfect, it could work well for many components. The custom styles are in risk of breaking with updates, but you can obviously control when you want to do your updates. |
The best solution I found for our organization is to include the entire CSS sheet from antd, with any styles that affect non antd named styles stripped out. Mileage might vary, and there is obviously the downside of every style now being imported. But it works well and I haven't seen any issues after doing so for about two months now. |
@jaleikas Using antd@3.10.2 here. |
this works for me |
Thank you for this solution! |
I chose to stop using antd, and decided to pick some unstyled components (like rc-switch). The problem is that most of the "unstyled" components are either horribly/not documented, and some of them also seem to behave differently, so for the most part, I gave up and looked elsewhere... |
@tylik1 , thank you! i just needed to fix the font-family to match the rest of my electron app. this totally saved me. |
it work for me by the following.
|
Unfortunately this is a show stopper. I will also not implement Antd even though the date picker is the best I could find so far. |
We are currently searching for a react component library for our company and this is also a blocking issue for us, and we probably an not use ant because of it. We are also looking at react MUI, which has great theming options, maybe you can have a look at how they do it and implement something similar. |
I used https://www.npmjs.com/package/patch-package to comment out
from |
It was 2020, humanity died out, coronavirus, ant-design adds global styles to the project... |
Tracking in #9363 |
Thanks for this great library!
I tried to use
babel-plugin-import
to do modular CSS imports, but along with the css for an individual component, there is a lot of global css being imported that interferes with my existing styles. Is it possible to import the CSS for an individual component without global CSS being included?Thanks!
The text was updated successfully, but these errors were encountered: