简体   繁体   中英

How to add a CSS file to a ASPX (Sharepoint Online)

When I try to edit my.aspx page within site pages I cannot get it to load my custom CSS file.

Sharepoint 2013 forces me to open the.aspx as an advanced file or else I cannot edit it.

The file then appears like the following

<%@ Page language="C#" Inherits="Microsoft.SharePoint.WebControls.ClientSidePage, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=#######" %><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=#######" %>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:######"><head>
<meta name="WebPartPageExpansion" content="full" />
<!--[if gte mso 9]>
<SharePoint:CTFieldRefs runat=server Prefix="mso:" FieldList="FileLeafRef,ClientSideApplicationId,PageLayoutType,CanvasContent1,BannerImageUrl,BannerImageOffset,PromotedState,FirstPublishedDate,LayoutWebpartsContent,_TopicHeader,_SPSitePageFlags"><xml>
    
    
    
        
    
    
<mso:CustomDocumentProperties>
<mso:PageLayoutType msdt:dt="string">Article</mso:PageLayoutType>
<mso:_SPSitePageFlags msdt:dt="string"></mso:_SPSitePageFlags>
<mso:CanvasContent1 msdt:dt="string">PAGE CONTENT</mso:LayoutWebpartsContent>
<mso:_AuthorByline msdt:dt="string"></mso:_AuthorByline>
<mso:display_urn_x003a_schemas-microsoft-com_x003a_office_x003a_office_x0023__AuthorByline msdt:dt="string">NAME</mso:display_urn_x003a_schemas-microsoft-com_x003a_office_x003a_office_x0023__AuthorByline>
</mso:CustomDocumentProperties>
</xml></SharePoint:CTFieldRefs><![endif]-->
<title>SITE TITLE</title>
</head>

I have then added <link rel="stylesheet" href="SITEURL/StylesSheetNew.css"> within the head

The CSS does not load when I view the page, I have ready many resources and am banging my head against a wall, what am I doing wrong?

You could use SPFX extension to inject js/CSS to SharePoint Online modern page.
Demo: https://github.com/hugoabernier/react-application-injectcss 在此处输入图像描述 在此处输入图像描述

are you using Sharepoint Online (your Title) or Sharepoint 2013 on-premise (your description)?

For sharepoint online - it is not Supported to insert css or JavaScript. You can use:

  1. Application customizer extension. For example: https://tahoeninjas.blog/2018/05/08/inject-custom-css-on-sharepoint-modern-pages-using-spfx-extensions/
  2. modern script editor - https://github.com/pnp/sp-dev-fx-webparts/tree/master/samples/react-script-editor . Install it, add it to a page and you can add CSS styling through <style> tags

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM