create-react-app中的条件CSS [英] conditional css in create-react-app

查看:51
本文介绍了create-react-app中的条件CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有默认的css文件和单独的css文件,仅当满足某些条件时才应应用(以提高默认值).

I have default css file and separate css file that should be applied (to owerride default) only when certain conditions are met.

我正在使用带有默认 import'file.css'语法的create-react-app.

I am using create-react-app wit default import 'file.css' syntax.

决定是否动态加载特定CSS文件的最佳方法是什么?

What is the best way forward to decide whether to load or not load particular css file dynamically?

推荐答案

您可以改为使用 require('file.css')语法.这将使您可以将其放在条件中.

You can use require('file.css') syntax instead. This will allow you to put it inside of a conditional.

例如

if(someCondition) {
    require('file.css');
}

这篇关于create-react-app中的条件CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆