Activity Forums Salesforce® Discussions How to add css file to static Resources ?

  • Radhakrishna

    Member
    April 19, 2017 at 5:36 am

    You can use relative paths in files in static resource archives to refer to other content within the archive. For example, in your CSS file, named styles.css, you have the following style:
    table { background-image: url('img/testimage.gif') }

    When you use that CSS in a Visualforce page, you need to make sure the CSS file can find the image. To do that, create an archive (such as a zip file) that includes styles.css and img/testimage.gif. Make sure that the path structure is preserved in the archive. Then upload the archive file as a static resource named “style_resources”. Then, in your page, add the following component:
    <apex:stylesheet value="{!URLFOR($Resource.style_resources, 'styles.css')}"/>

    Since the static resource contains both the style sheet and the image, the relative path in the style sheet resolves and the image is displayed.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos