create react app not loading css background images in dev or build

前端 未结 3 1600
执念已碎
执念已碎 2021-02-20 07:39

I\'m having difficulty with some background images not loading. I\'ve made some significant modifications to the initial create react app, my folder structure is now as follows

相关标签:
3条回答
  • 2021-02-20 07:55

    The issue was purely an issue with CSS in the App.css file:

    App.css

    .trees__tree {    
        background: url('../images/tree.png') no-repeat;
        background-size: 30px; /** moved this property down */
        float: left;
        height: 50px;
        width: 30px;
    }
    
    0 讨论(0)
  • 2021-02-20 08:08

    My issue was specifically that I did not have background-size: 30px; defined. Thanks for this.

    0 讨论(0)
  • 2021-02-20 08:11

    Add homepage in package.json to run build in any apache server

    {
      "name": "app",
      "version": "0.1.0",
      "private": true,
      "homepage": "http://{servername}/{foldername}/",
    
    }
    

    then create build in react using

    1. npm run build
    2. npm install -g serve
    3. serve -s build
    4. Copy build folder and paste in server like xampp/htdocs and hit url
    0 讨论(0)
提交回复
热议问题