create-react-app 2.x 中css 模块化

alonwang

关注

阅读 178

2022-10-10


# 1 css文件写成 xxx.module.css 如果使用sass 写成 xxx.module.scss
.test h3 {
color:rgba(166, 169, 253, 1.000);
}

# 2 组件中引入
import React, { Component } from 'react';
import styles from './aaa.module.css'

class Com1 extends Component {
render() {
return (
<div className={styles.test}>
<h3>回家看电视看见粉红色的空间</h3>
</div>
);
}
}

export default Com1;

# 浏览器渲染过后
# html
<div class="aaa_test__1FvHW">
<h3>回家看电视看见粉红色的空间</h3>
</div>

# css
.aaa_test__1FvHW h3 {
color:rgba(166, 169, 253, 1.000);
}


精彩评论(0)

0 0 举报