Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1549

How to import image and use in css in sveltekit

$
0
0

I'm using sveltekit and I'm wondering how to import an image and use it in a CSS background property.
Here's what I've tried:

<script>    import img from '$lib/images/background-shaded.jpg';</script><div><h1>Hello World</h1></div><style>    div {        background-image: url({img});    }</style>

For now, I'm just putting the image in the the static folder and using via it's URL. Maybe that's the recommended approach...

Thanks.


Viewing all articles
Browse latest Browse all 1549

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>