Add css to masterpage (SharePoint Online/Office 365)
-
04-10-2020 - |
Question
I have a css to hide list search box on document libraries. It's in the SiteAssets library.
I can edit a document library view and add Content Editor webpart and add css reference and able to hide.
However, I added following code to masterterpage after core.css
but it doesn't fire. Any idea why?
<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/SiteAssets/hideSearchBox.css%>" runat="server" After="corev15.css" />
The css is
<style>
.ms-inlinesearch-divbaseline{ display: none !important;}
</style>
La solution
You need to enable publishing features on the site collection (SP_Site) and on the web (SP_Web) and set the alternate CSS URL to your css-file.
- Find "Site Collection Features" setting and enable all features with name "publishing" in it.
- Find "Manage Site Features" setting and enable all feature with name "publishing" in it.
- Find "Master Page" setting link under "Look and Feel".
- Click "Alternate CSS URL". This is where you apply your own CSS file.
- Upload a CSS file to any document library. Ideally to "Style Library".
- Go to step 4 and choose your uploaded CSS file.
Source: Most upvoted answer to the question "CSS and master page - Sharepoint online - Office 365"
Autres conseils
If you are trying to add in the HTML page (ex: seattle.html) then use the below code
<!--MS:
<style type="text/css">-->
.ms-inlinesearch-divbaseline{ display: none !important;}
<!--ME: </style>-->
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange