Webpack - background images not loading

后端 未结 8 1883
渐次进展
渐次进展 2020-12-09 15:34

I\'m fairly new to webpack but having some problems with css-loader or file-loader.

I\'m trying to load a background-image but it doesn\'t work quite right. The bac

8条回答
  •  渐次进展
    2020-12-09 15:45

    It seems like browsers aren't fond of relative paths to background images on the body tag. (see also CSS Background image not loading and css background-image not working properly)

    Changing the code slightly seemed to do the trick:

    • change the URL to an absolute URL: background-image: url(http://localhost:8080/5a09e4424f2ccffb6a33915700f5cb12.jpg). This is hardly ideal.
    • add a class to body, and change the styles to reference this class:
    
    
    .foo {
        background-image: url('../img/test.jpg');
    }
    

    Neither of these solve the real question, but do get you unstuck.

提交回复
热议问题