Unable to use background image #10387
-
|
Hi all, // running versions
"tailwindcss": "^3.0.23",I'm at a complete loss. I am trying to include an image as a background image and have tried a variety of approaches to no avail. I have tried:
// tailwind.config.js
backgroundImage: {
"image-of-banana": "url('../public/image-of-banana.png')",
},
// app/routes/bananaPage
<div className="... bg-[url('../../public/image-of-banana.png')] bg-cover bg-center bg-no-repeat ..." />Nothing works. I get a Strangely, requesting the same image via the Could someone please help me to find the error in my ways? Thanks for all the help. References
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Consider matching the path inside the |
Beta Was this translation helpful? Give feedback.
-
|
Make sure the URL matches the actual URL where the image is being served from, not the path to the image on your local machine. Usually the public directory is just served from root on your server, so my guess is the right path is just If you are going to ever use relative URLs (I would recommend against it), they should be relative to where the compiled CSS file lives, not relative to your template file. |
Beta Was this translation helpful? Give feedback.
Make sure the URL matches the actual URL where the image is being served from, not the path to the image on your local machine. Usually the public directory is just served from root on your server, so my guess is the right path is just
url(‘/image-of-banana.ping’)or maybeurl(‘/public/img-of-banana.png’).If you are going to ever use relative URLs (I would recommend against it), they should be relative to where the compiled CSS file lives, not relative to your template file.