I have found many articles and solutions on adding multiple css classes to a React div.
However I can’t find anything explaining how to apply multiple classes when one class comes from a module and the other doesn’t.
My js component imports two stylesheets.
import styles from "./text-image-section.module.scss";
import "../../animate.scss";
I am trying to apply both classes to a div
<div className={`${styles.textContainer} .animate`}>
2
Answers
When accessing a module’s class, string interpolation is usable, as you’re importing it into a variable
styles
(as opposed to a plain string).However, when access a non-module class, you can just put the name of the class down.
So, for your case, instead of putting
<div className={`${styles.textContainer} .animate`}>// content...</div>
,you can put
<div className={`${styles.textContainer} animate`}>// content...</div>
This is assuming "animate" is a class inside of
"../../animate.css"
You can import global classnames the same way you import scoped classnames.
resulting DOM