3

I started working on Craft today. I want to display a background CSS image by adding a rule.

Should I manually copy the file in assets folder or there's some way to upload and refer it on page.

3

If you need the background image to be dynamic and controlled by the client then I would recommend using inline CSS in the template to set the image path. The rest of the required CSS can be in the CSS file itself.

e.g.,

<div style="background-image: url('{{ entry.image.first().getUrl('transformName') }}')" class="thing" ... >

Your CSS file could even have a fallback background-url and in your CSS

.thing { background-size: cover; ... }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.