0

Sorry if this could already have been answered but I am new to Sharepoint Online.

With previous versions of Sharepoint, this has been working fine for me until now.

  1. Upload an HTML, CSS and JS files within any document repository in Sharepoint
  2. Call the CSS and JS files using traditional src="/RelativePathToTheCSSandJSFiles"

With Sharepoint online, this seems to no longer work. For testing purposes, what I do now is this:

  1. Upload .ASPX file within the default Document folder of a site collection I created
  2. Upload the CSS and JS files within the default Style Library Folder

enter image description here

  1. Called the CSS file using the following script

enter image description here

  1. Called the JS file using the following script

enter image description here

Am I doing this the right way? Please help.

Alex M
  • 103
  • 1

1 Answers1

0

Consider using <SharePoint:CssRegistration> content placeholder, which defines the CSS file:

<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/CSSTest.css%>" runat="server"/>

And at runtime:

<link rel="stylesheet" href="/sites/KnowledgeManagement/Stype%20Library/CSSTest.css" type="text/css" media="all" />

References:

Use CSS to brand SharePoint pages.

SharePoint CSSRegistration or Link?

Chelsea_MSFT
  • 4,542
  • 1
  • 6
  • 10
  • Thanks Chelsea_MSFT. Sorry but I am new to this. Given the structure I have shown above, where do I input the SharePoint:CssRegistration code? Can I put that within the ASPX file I created within the Documents folder? – Alex M Jun 01 '20 at 16:21
  • 1
    @AlexM If you just want to call the css file within one aspx file, the line you provide in the original post should work as expected. Another reference: https://sharepoint.stackexchange.com/questions/221030/how-to-put-a-reference-for-a-css-in-aspx-page-layout-in-sharepoint-2016 – Chelsea_MSFT Jun 02 '20 at 06:35
  • Absolute URL to the CSS file worked! Thanks! – Alex M Jun 04 '20 at 19:59