Skip to content

Adding a background-image for a html element #1975

Answered by Fil
nunglert asked this question in Q&A
Discussion options

You must be logged in to vote

You could use a dynamic HTML code block:

```html
<style>
.hero {background-image: url(${FileAttachment("./img.png").href})}
</style>
```

(Note that I'm using the synchronous attribute file.href instead of the asynchronous method file.url() — both work equally but it feels simpler that way.)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nunglert
Comment options

Answer selected by nunglert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants