You could add js code to determine whether the page is the target page.If it is,then add the custom css(Use CSS to hide left navigation).
Demo:
if ((window.location.href.toLowerCase().indexOf('testfolder') > 0))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = 'https://contoso.sharepoint.com/sites/dev/Doc/testFolder/test.css';
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
Inserting this code needs to distinguish different types of pages:
- Modern page:you need to use SPFX Extension to add JS file.
- Classic page:you could add this file to global jslink.
pnp powershell:
$username = "[email protected]"
$password = "Password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred
Add-PnPJavaScriptLink -Name "JSLoadAfterSP" -Url /sites/dev/Doc/testFolder/test.js -Sequence 9999 -Scope Site
Similar issue:
How to use JS to inject CSS for specific system pages
https://docs.microsoft.com/en-us/answers/questions/70373/customization-colour-document-header.html
SPFX Extension add js file:
https://github.com/Amos-IT/SharePoint-FrameWork-Demos/tree/master/react-application-injectjs-master