#How do I use an imported image as a Tailwind or CSS Background image?
8 messages · Page 1 of 1 (latest)
You can't use a variable inside url(), the variable has to include the url like: --var: url('/path')
You can try this instead: ```jsx
import bg from "~/assets/images/image.jpg";
<style define:vars={bg-url: url(${bg}}}>
.hero {
background-image: var(--bg-url);
}
</style>
This didn't work either. If it's easier, is there a way to use a prop/variable as a background image in an inline style tag?
I've tried this but it's still not working..
<div class="hero" style="background-image: url(${bg});">
ya you could try ```
style={background-image: url(${bg});}
oo it worked!
This also might not be working because images in the Nvm/src folder are bundled and renamed, you could try moving your image to the /public folder