I’m trying to build a simple landing page the traditional way, using JS, HTML and CSS. I have a folder with assets, including images. I want to use one of those images as a background image for one of my CSS selectors.
When running the app locally the image loads fine but it won’t work when running it from anvil, for some reason.
I suspect you haven’t gotten any suggestions because there’s not enough context for us to be able to understand. You say you’re writing a landing page the traditional way, i.e. without Anvil, but then you’re trying to run it inside Anvil?
If you have a clone link to demonstrate the app that isn’t working, post it to give people something concrete to play with.
I’m sorry maybe I didn’t formulate the question in the proper way. To put it in different words: I’m wondering why does the image in the URL shown In my CSS excerpt doesn’t show up when I run the app on anvil but It does work when I run it locally. Hope this helps.
I would recommend moving css like this into the theme.css file
Anvil loads this with the html
that way css in theme.css doesn’t need to be fetched after the page has loaded
and you will avoid the flash of unstyled content (FOUC)
If you move everything from theme/style.css into theme.css your original version will work as expected, and you will avoid the FOUC.
The FOUC was definitely solved by placing my styling inside theme.css. However image still won’t load using the relative path. Poking around, the only thing that worked was moving the image at the root _theme/ and referencing like this: url('./candles.jpg').