![](/img/trans.png)
[英]Is CSS 3 Transition do not work with Template element (HTML 5) in case of Adding Class…?
[英]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>
如何将styles['second-style']
添加到类名中? 我试过逗号,它不起作用。
解决了它:
<div className={`${styles['first-style']} ${styles['second-style']}`}>
我更喜欢使用类名 npm 模块https://www.npmjs.com/package/classnames
你可以用这种干净的方式做更复杂的事情。
import classNames from 'classNames'
const condition = true;
<div className={
classNames(
styles.first-style,
styles.second-style,
{'styles.some-other-conditional-classname': condition})}>
您也可以使用clsx 。
const Toolbar = ({
className,
...rest
}) => {
<Component
className={clsx(classes.root, className)}
{...rest}
>
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.