Creating personalized CSS for Sharepoint online site customization

While looking into supported and unsupported customization options and custom CSS for branding in SharePoint online, I found myself perplexed by the vague and confusing information provided by Microsoft's articles.

Specifically, I was studying the application of custom CSS through alternate CSS in a publishing site and came across this article:

https://msdn.microsoft.com/en-us/pnp_articles/portal-branding

Within this article, there is a point under "General Principles" that lacks clarity and detailed explanation.

General Principles

When it comes to branding portals in a SharePoint Online environment, developers should consider the following general principles:

The SharePoint Online service is constantly evolving. Updates to the service may impact the DOM structure of out-of-the-box pages and the content of out-of-the-box files (such as master pages). Developers need to be aware of this and avoid relying on unsupported customization methods (e.g. positioning of specific elements within the DOM structure of a page).

In the above point, it states: Developers need to avoid relying on unsupported customization methods, such as positioning specific elements within the DOM structure of a page. - But what does this really mean? Does this pertain only to custom CSS applied through alternate CSS URL on certain web part pages, where the CSS is limited to web part zones and out-of-the-box web parts within?

Can someone provide clarification? I am seeking an expert opinion. Does the aforementioned statement only relate to the Office 365 bar DOM and its CSS, or does it also apply to the DOM of out-of-the-box web part pages? If so, how? Could someone offer an example? I have written custom CSS and applied it through an alternate CSS URL, mostly changing the appearance of web part zones and out-of-the-box list view web parts within them (e.g. color, width, larger fonts, etc).

Answer №1

This discussion doesn't seem to be directly related to SharePoint or the use of an external CSS stylesheet. Let's take a moment to analyze the language:

"Developers [...] should not rely on [...] position of specific element in DOM structure of the page"

It seems like Microsoft is cautioning against targeting elements based on the DOM structure using CSS or JavaScript, rather than using element ID or class. For example, the selector p + div targets any <div> element immediately following a <p> element.

Here's a scenario where it works:

p + div {
  color: red;
}
<p>Text</p>
<div id="div">More text</div>

And here's a scenario where it doesn't work:

p + div {
  color: red;
}
<p>Text</p>
<a>Link</a>
<div id="div">More text</div>

Simply shifting the position of the #div element in the DOM caused the selector to stop functioning. This seems to be the concern raised by Microsoft.

Instead, it may be safer to directly target the desired element using # for ID selection:

#div {
  color: red;
}
<p>Text</p>
<a>Link</a>
<div id="div">More text</div>

Of course, there will be instances where you may not have an ID for an element, in which case you can utilize class selectors, attribute selectors, or type selectors. Focus on specificity and adapt accordingly, aiming to minimize dependence on context as much as possible.

I hope this explanation is helpful! :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enabling visibility of overflowing text in dynamically inserted divs without using scroll bars

Is there a way to set the text overflow to visible without scroll bars in dynamically added <div>s? Despite what the documentation says, it doesn't seem to be the default behavior and I'm struggling to understand why. Adding text directly t ...

Exploring the power of pseudo elements within Angular5

What could be causing the issue with regular pseudo-classes from CSS not functioning as expected in Angular5? One workaround is to replicate their behavior using Angular event handlers such as (click)="function1()" or (mouseenter)="function2()". Why is it ...

Navigate through the contents of a table featuring intricate colspan and rowspan elements, while keeping both headers and left columns in

I am facing a challenge with a dynamically generated table that has complex structure including colspans and rowspans. My goal is to fix the headers and, if possible, even lock the first few rows on the left side while allowing the content of the table to ...

Tips for keeping the hover effect of a sibling element in Material-UI

Card Component import image from "../../Assets/pic.jpg"; import React, { useState } from "react"; import { makeStyles } from "@material-ui/core/styles"; import Card from "@material-ui/core/Card"; import CardActionAre ...

invoke two JavaScript functions without displaying any message

I'm facing an issue with Ajax as it's not displaying the message I intend to show. Let me elaborate. Within my PHP code, there is an input tag: <input type="submit" id="login_button_add" name="submit" value="Add" onclick="add_building(); sho ...

Convert Python strings into HTML JavaScript blocks using Jinja2

Having trouble passing a string to an HTML page in the "<script>" block. I am currently using Python, Flask, and Jinja2. Python code: def foo(): return myString #"[{title: 'Treino 7-Corrida',start: '2015-12-08',color: '#d ...

Issues with the OnChange function not properly functioning in duplicate input fields

I've designed a form that allows for adding or deleting rows, effectively cloning input fields. One of the input fields utilizes Jquery Ajax to retrieve its value. However, upon adding an extra row by cloning the parent row to generate a child row, th ...

Guide on making a custom page by substituting specific text with user-provided input based on an existing sample page

I'm looking to create a webpage with a form <form class="col s12" method="POST" action="addtask.php"> <div class="row"> <div class="input-field col s6"> <input placeholder="Username" id="user" type="text" class="v ...

Adjust the height of the outer div automatically

Currently, I am attempting to dynamically set the height of div#container so that it adjusts based on its relative positioning and the absolute positioning of inner divs. Essentially, I want the inner divs to be centered within the container. <div id=" ...

Unable to transmit form information using HTML/JavaScript/Express Node application

I'm facing a challenge in developing an app that allows me to input event information and then display it on a map. I'm encountering difficulties at the initial stage when it comes to saving the data. Even though Chrome's Inspect tool indica ...

Are inline styles being utilized in a Styled component?

I'm currently utilizing styled-components within a React project and I am having trouble finding documentation regarding whether or not a styled component can accept inline styles on the "style" property. For example: The Text component has been styl ...

Ensure each list item is directly aligned when swiping on a mobile device

Looking to make a simple horizontal list swipeable on mobile devices with tabs that snap from tab to tab, activating the content for the active tab immediately. The desired effect is to swipe directly from one tab to the next without having to click separ ...

What is the best way to center align and add an icon to the header in Ionic?

How can I center align an "ion-ios-arrow-up" icon in the header of my Ionic app, similar to the concept shown below? This is my HTML template: <ion-view cache-view="false" view-title="Historical HPP"> <ion-nav-bar class="nav-title-slide-ios7 ...

A clock for counting down on statically produced websites

It seems that I have encountered a limitation of statically generated sites. Currently, I am utilizing Gatsby to generate pages in a static manner. The process involves: Pulling data from the CMS where we set an end time for a countdown timer, such as two ...

How to specify columns when storing data in a CSV file using Scrapy

As I scrape data from the web, I am facing an issue with my csv file where the links column is always displayed as the first column. How can I specify the placement of columns in the csv file? pName = response.css('#search .a-size-medium') ...

Creating dynamic image carousels using the latest versions of Bootstrap and AngularJS

I have created an array that stores various images using angularJS: $scope.docImg = [ '../../Content/Image/BackGrounds/abra.png', '../../Content/Image/BackGrounds/background_black.jpg', '../../Content/I ...

Maintain the active menu open when navigating to a different page on the website

My website has a dropdown menu, but whenever I click on a submenu link, the new page opens and the menu closes. However, I want the active menu to remain open on the new page of the website! To demonstrate what I have tried in a simple way, I created an e ...

Eliminate borders for text input in Bootstrap 3 styling

Trying to eliminate the top, right, and left borders for text input fields in Bootstrap 3. The selector being used is as follows: input[type="text"] { border-top: 0; border-right: 0; border-left: 0; } However, in Chrome, a faint thin line is ...

Empty gaps separating two divs nested within another div within a div (unable to function)

I'm diving into the world of HTML, CSS, and JS as I embark on creating a weather application. My vision is to include the temperature, followed by the city and its corresponding weather (accompanied by an icon), and lastly additional details like humi ...

Div that scrolls independently without affecting the position of other elements

Visit this link for reference <div class="col-10 content" id="content"> <ul> <li>News</li> <li>News</li> <li>News</li> <li>News</li> < ...