简体   繁体   English

是否可以在我们的 React 网站中为不同的组件使用不同的 CSS 库?

[英]Is it possible to use different CSS libraries for different components in our react website?

For example , I have 3 components==> Home, About, Contact .例如,我有 3 个组件==> Home、About、Contact

Is it possible to use material ui css library for Home component, semantic ui css library for About component and bootstrap for Contact Component.是否可以将 Material ui css 库用于 Home 组件,将语义 ui css 库用于 About 组件,将 bootstrap 用于 Contact 组件。

If yes, then How?如果是,那么如何?

Sure you can, I think the better question is if you should.当然可以,我认为更好的问题是您是否应该这样做。
Mixing frameworks would likely lead to in inconsistent UX.混合框架可能会导致用户体验不一致。 That's something normally avoided for non-technical reasons.由于非技术原因,通常会避免这种情况。

Still, sometimes you need to transition things slowly, and might have different parts of your software look different.不过,有时您需要慢慢过渡,并且软件的不同部分可能看起来不同。

When you're certain you actually want to mix different ui frameworks, just follow the regular 'get-started' guides for those frameworks.当您确定您确实想要混合不同的 ui 框架时,只需遵循这些框架的常规“入门”指南即可。

here's a code-sandbox with both a mui-button and a bootstrap-button这是一个带有 mui 按钮和引导按钮的代码沙箱

import * as React from "react";
import * as ReactDOM from "react-dom/client";
import Button from "@mui/material/Button";
import { Button as BootstrapButton } from "react-bootstrap";

import "bootstrap/dist/css/bootstrap.min.css";

function App() {
  return (
    <>
      <Button variant="contained">Hello World</Button>
      <br />
      <br />
      <BootstrapButton variant="primary">Primary</BootstrapButton>
    </>
  );
}

ReactDOM.createRoot(document.querySelector("#app")).render(<App />);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM