所以我刚刚开始学习 React,我正在尝试合并一个 CSS 文件来设置一个 React 组件(即侧边栏)的样式,但我不确定为什么网页上没有显示任何样式。我已经尝试在 index.js 文件中内联 css 并且它有效,但我正在尝试将所有样式代码移动到 css 文件中。我安装了一个 sass 加载器和 css 加载器,并将它们包含在 webpack.config.js 文件中。我只是忘记了一些愚蠢的事情吗?
这是我的 style.css 文件
.sidebar {
position: fixed;
height: 200px;
font-size: 20;
width: 60px;
background-color: deepskyblue;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: azure;
}
li {
display: block;
color: gray;
padding: 8px;
font-size: 20;
text-decoration: none;
}
li :hover {
background-color: forestgreen;
}
还有我的 index.js 文件
import React from 'react'
import {styles} from './style.css'
import Home from './home.js'
export class Sidebar extends React.Component {
render() {
return (
<div className={styles.sidebar}>
<ul>
<li>Home</li>
<li>Test1</li>
<li>Test2</li>
</ul>
</div>
)
}
}