[英]Adding two kebab case css class in an element in react
import React from 'react';
import styles from './stylesheet.moudle.css'
<div className={styles['first-style'] styles['second-style']}>
some content
</div>
How do I add styles['second-style']
into the className?如何将
styles['second-style']
添加到类名中? I tried comma and it does not work.我试过逗号,它不起作用。
Solved it with:解决了它:
<div className={`${styles['first-style']} ${styles['second-style']}`}>
I prefer using classnames npm module https://www.npmjs.com/package/classnames我更喜欢使用类名 npm 模块https://www.npmjs.com/package/classnames
You can do more complex things with this in a clean way.你可以用这种干净的方式做更复杂的事情。
import classNames from 'classNames'
const condition = true;
<div className={
classNames(
styles.first-style,
styles.second-style,
{'styles.some-other-conditional-classname': condition})}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.