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

Can I set svelte style css attribute values using variables passed in to a component

$
0
0

I want to create a svelte component that receives the name and path of an image. I want to have the component set the image as the "background-image" using CSS.

I've tried the following which does not seem to work...

Component called in App.svelte:

<Image image_url='./images/image1.jpg' />

Image.Svelte

<script>export let image_url;</script><style>.image{    position:relative;    opacity: 0.70;    background-position:bottom;    background-size: cover;    background-repeat: no-repeat;    background-attachment: fixed;    background-image: url({image_url});    min-height: 100%;}</style><div class="image"><p>some text</p></div>

When I inspect the component the css for background_image is:

background-image: url({image_url});

Is it possible to have the variable converted in the CSS?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



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