【问题标题】:Error when trying to add background image in react js尝试在 React js 中添加背景图片时出错
【发布时间】:2021-10-02 11:02:03
【问题描述】:

尝试在 react js 中添加背景图片时出现错误。

  ./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
    Module not found: You attempted to import ../public/img/bg.jpg which falls outside of the project src/ directory.
    Relative imports outside of src/ are not supported.

我的 CSS:

   section{
      position: fixed;
      top: 0;
      left: 0;
      height: 100vh;
      background: url("../public/img/bg.jpg");
      background-attachment: fixed;
    }
    .container{
      position: relative;
      margin-top: 200vh;
      background: #fff;
      padding: 100px;
    }

【问题讨论】:

标签: javascript html css node.js reactjs


【解决方案1】:

尝试在您的 HTML 标记中使用之前使用 '../image.jpeg' 在您的组件中导入此图像,或从公用文件夹中删除文件夹图像,我相信以这种方式使用您需要更改默认值公共文件导出设置。

在这里您将找到与您的问题相关的更多信息Link

【讨论】:

    猜你喜欢
    • 2014-11-07
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2013-09-05
    • 2018-01-16
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    相关资源
    最近更新 更多