简体   繁体   English

在React中更改样式表

[英]Changing Stylesheets in React

I'm working on a React app. 我正在开发一个React应用程序。 I have a few different stylesheets to restyle the same elements. 我有一些不同的样式表来重新样式相同的元素。 Let's say for sake of this question I have two that have identical elements but different styles. 假设出于这个问题,我有两个元素相同但样式不同的东西。 Right now, in the app, I just import it with: 现在,在应用程序中,我只需使用以下命令导入它:

import './Stylesheet1.css'; 导入'./Stylesheet1.css';

What I'd like to do is, based on a setting for that customer in a database, it would switch to using ./Stylesheet2.css instead. 我想做的是,根据数据库中该客户的设置,它将改为使用./Stylesheet2.css。

I know there are extra modules to include out there that may help and I could do things with dynamically building stylesheets and I may need to go to those options, but for now, I'd like to see if there is simply some way to dynamically swap out which CSS file I'm pointed to. 我知道这里有一些额外的模块可能会有所帮助,我可以通过动态构建样式表来做一些事情,我可能需要使用这些选项,但是现在,我想看看是否有某种动态方法换出我指向的CSS文件。

Well another way you can do this is as follow: 那么,您可以执行以下另一种方法:

import style1 from './Stylesheet1.css'; 从'./Stylesheet1.css'导入style1; import style2 from './Stylesheet1.css'; 从'./Stylesheet1.css'导入style2;

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

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