css - 媒体查询不适用于 CSS/样式加载器和 Webpack3

标签 css reactjs webpack-style-loader css-loader webpack-3

我正在为我的CSS使用css-loaderstyle-loader,但所有媒体查询都不起作用。我正在使用 "webpack": "^3.4.1""css-loader": "^0.28.4""style-loader": “^0.18.2”

这是我的 Webpack 配置:

const ExtractTextPlugin = require('extract-text-webpack-plugin')

rules: [{
  test: /\.css$/,
  use: [{
    loader: 'style-loader'
  }, {
    loader: 'css-loader',
    options: {
      modules: true,
      localIdentName: '[name]-[local]-[hash:base64:6]',
      camelCase: true
    }
  }]
}]
...
plugins: [
  new ExtractTextPlugin({
    filename: 'style.[chunkhash:6].css',
    allChunks: true
  })
]

我的CSS文件是这样的:

.container{
  position: relative;
  margin: 30px 15px;
  padding: 50px 15px;
  background: #fff;
}
@media (max-width: 768px) {
  .container{
    background: #fbfbfb;
  }
}

我在 React 代码中导入这个 CSS 文件,如下所示:

import styles from './Component.css'

最佳答案

尝试使用此代码

.container{
  position: relative;
  margin: 30px 15px;
  padding: 50px 15px;
  background: #fff;
}
@media only screen and (max-width:768px){
  .container{
    background: #c00;
  }
}
<div class="container">
content her
</div>

关于css - 媒体查询不适用于 CSS/样式加载器和 Webpack3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45431640/

相关文章:

css - 更改 CSS 动画中伪元素的内容属性

javascript - Redux Reducer 正在返回一个 [Object Object] ,但是我想要字符串?

javascript - React Native 动态 webview 高度

Webpack:我必须在 publicPath 中为 url() 指令指定域才能在 CSS 中工作吗?

javascript - Twitter 的 typeahead.js 建议没有样式(没有边框、透明背景等)

css - 视口(viewport)元标记在移动 safari 中无效

reactjs - ReduxForm 装饰器,弹出 create-react-app 后出现无类分配错误

javascript - Webpack 未构建 css 文件

javascript - webpack4 css 捆绑不适用于自定义样式名称

html - Ace Editor 未随容器 div 调整大小