【发布时间】:2019-10-05 17:57:50
【问题描述】:
我在reactjs中有入口组件:
import React from "react"
import ReactDOM from 'react-dom';
import App from "./js/components/App.js"
import './index.css';
ReactDOM.render(<App />, document.getElementById('root'));
我正在尝试在我的 css 文件 index.css 中的根元素中设置样式:
#root {
background-color: brown;
height:100vh;
width:100vh;
}
虽然背景不是棕色的。在查看浏览器呈现的样式时,我看不到任何这些属性应用于根元素。
这是我的 webpack 配置:
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.css$/,
use: ['css-loader'],
},
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
})
]
};
就好像根本没有加载index.css文件一样。
【问题讨论】:
-
你应用了两次背景色。
-
对不起,这是我调试时的一种类型。立即删除