background image not importing correctly #38010
Replies: 6 comments 10 replies
-
did you get any solution? having the same problem but i hosted my project on github |
Beta Was this translation helpful? Give feedback.
-
I tried this, it does work. Hope it can help u. |
Beta Was this translation helpful? Give feedback.
-
i tried that too it worked when my website wasnt live when i hosted it the background image wouldnt show up do you know ow to solve that? also all the other images ta=hat arent background images work fine |
Beta Was this translation helpful? Give feedback.
-
I faced the same problem when deploying website to vercel , |
Beta Was this translation helpful? Give feedback.
-
An alternative is to use inline styles in addition to the class: import img from '../assets/images/image.jpg'
//...
<div style={{
backgroundImage: `url(${img.src})`,
}}
className={style.bg_img}></div> |
Beta Was this translation helpful? Give feedback.
-
Try changing the URL syntax, in my case '/' was missing at the beginning but still img is visible on localhost but not after hosting. Try changing url of the image by inspecting the page, maybe it could work. |
Beta Was this translation helpful? Give feedback.
-
This is one of the line in my index.js code
<div className={style.bg_img}></div>
corresponding css code
in the above line i'm setting a backround image for that div element and i'm importing the styles very correctly
when i host it in my localhost everything works good and when i inspect the element i'm getting this results
but when i host my page in vercel for production the backround image is not importing properly and i'm rendering with some different url
and other than index.js page the background works very well
Beta Was this translation helpful? Give feedback.
All reactions