I have a static component where the content is loaded dynamically as html. The lightning component provides some styles to present that content. I would like to provide icons, images that are defined as 'Static Resources' to that content from css. Like if there is a div with class 'warningDiv' then the css can be,
.THIS .warningDiv {
background-image: url('warning.png')
}
I tried adding the image as static resource and using the name of static resource like background-image: url('warning.png')
and as well as using the $Resource expression background-image: url('!$Resource.resourcename')
but both don't work.
Then I tried adding the image in an archive, load that in component using ltng:require but as styles and then tried to the image in css. That didn't work as well,
<ltng:require styles="/resource/my_resources"
afterScriptsLoaded="{!c.init}" />
.THIS .warningDiv
{
background-image: url('./warning.png');
}
but maybe I am doing it wrong.
I know one of the work around is to modify the content and have but I would want to avoid that as it would mean modifying lot of content.
Is there a way to refer static resource images in css for lightning component?
/resource/resourcename/imagename.ext
should work.