#Background image not working unless using the full, hardcoded url

1 messages Β· Page 1 of 1 (latest)

chrome adder
#

Does anyone have best practices around using background images? I tried using tailwind's bg-[url()] property, but it only works if I hardcode an external URL. I can't even get it to work with css. For example, I'm setting background-image: url('/public/img/aerial.jpg'); and vite correctly adds it to manifest.json. When I inspect the element in the iPhone simulator is has background-image: url(/build/assets/aerial-Dmwjxc-y.jpg); but the image still gives a 404 even though the file exists.

sinful tundra
#

Use the asset() helper

chrome adder
#

tried that too. for some reason style="background-image: url({{ asset('img/aerial.webp') }});" ended up working but class="bg-[url({{ asset('img/aerial.webp') }})]" gave a 404.