SlideShare a Scribd company logo
SASSY WEB PART IN SPFX
Stefan Bauer
Information Architect N8D
DIAMOND, PLATINUM AND GOLD SPONSORS
OUR GOALS
 SASS base concepts
 Sketch & develop web parts
 Create your own reusable CSS
 Handle external CSS properly in
SPFx
 Apply themes to your web parts
TYPESCRIPT
is a typed
superset of
JavaScript that
compiles to
JavaScript
SASS –
SYNTACTICAL AWESOME STYLE
SHEETS
is a superset and
programming
language
of CSS that
compiles to CSS
PROGRAMMING LANGUAGE?
VARIABLES
$brand-color-main: #DD304D
$default-padding: 10px
TYPES
numbers:
1.2, 13, 10px
strings:
"foo", 'bar', baz
colors:
blue, #04a3f9, rgba(255, 0, 0, 0.5)
boolean, null, lists of values, maps
PROGAMMING
@if
@else
@for
@each
@while
@debug
@warn
@error
MORE FEATURES? - FUNCTIONS
@function addition($a, $b) {
@return $a+$b;
}
// Function
a {
padding: addition(10px, 30px);
}
// Result
a {
padding: 40px;
}
MORE FEATURES? - MIXIN
@mixin headline ($color, $size) {
color: $color;
font-size: $size;
}
h1 {
@include headline(green, 12px);
}
// Result
h1 {
color: green;
font-size: 12px;
}
PLACEHOLDER EXTEND
// Template Definition
%box{
display: block;
width: 300px;
height: 150px;
}
PLACEHOLDER EXTEND
// Red Box
.red-box{
@extend %box;
background-color: red;
}
// Green Box
.green-box{
@extend %box;
background-color: green;
}
PLACEHOLDER EXTEND - RESULT
.red-box, .green-box {
display: block;
width: 300px;
height: 150px;
}
.red-box {
background-color: red;
}
.green-box {
background-color: green;
}
NESTING - PARENT SELECTOR - &
a{
color: teal;
&:hover{
color: pink;
}
&:visited{
color: teal;
}
}
NESTING
a{
color: teal;
}
a:hover{
color: pink;
}
a:visited{
color: teal;
}
NESTING – PARENT SELECTOR - &
.box{
display: inline-block;
width: 300px;
height: 200px;
color: black;
&-label{
height: 50px;
background-color: black;
color: white;
}
}
NESTING – PARENT SELECTOR - &
.box{
display: inline-block;
width: 300px;
height: 200px;
color: black;
}
.box-label{
height: 50px;
background-color: black;
color: white;
}
Create SASSy web parts in SPFx
LEAST IMPORTANT FEATURE IN
HTML
@import url("fineprint.css") print;
@import url("bluish.css") projection, tv;
@import 'custom.css';
@import url("chrome://communicator/skin/");
@import "common.css" screen, projection;
@import url('landscape.css') screen and (orientation:landscape);
@import url;
@import url list-of-media-queries;
HOW BROWSER HANDLE
1. Load CSS
2. finds @import
3. Load CSS
4. parse both CSS
5. Render page
HTTP
Request
HTTP
Request
MOST IMPORTANT FEATURE IN
SASS
Works same as in HTML but different
@import url(‘http://getbootstrap.com/someurl’)
HTML import
@import ‘somefile.css’
Merges file directly into CSS
@import <file | url>;
MOST IMPORTANT FEATURE IN
SASS
•Partial file through the ‘_’
•File won’t be compiled to ’.css’ file
•Import Reusable components
•Helps you strucuture your CSS Better
@import ‘_custom.scss’;
@import ‘custom’;
IMPORT IN SPFX
•Import CSS from any npm package
•Import CSS from bower components
@import ‘_custom.scss’;
@import ‘custom’;
@import ‘node_modules/office-ui-fabric/dist/fabric.css’
THAT’S ALL ABOUT
SASS
HOW I WORK
Create SASSy web parts in SPFx
Create SASSy web parts in SPFx
Create SASSy web parts in SPFx
MYWORKFLOW
SKETCH AND DESIGN
DOCUMENT STYLES
MOVE IT TO SPFx / SharePoint
DOCUMENT STYLES
•StyleGuides.io
•Pattern Library
•Simple Style
for SP/O365 and SPFx
•React Components
DEMO
BENEFITS
-Focus on code design
-Reusable components
-Cross browser testing
-No documentation effort
- Refactor components
Common Tool in Web Design
BRING IT
TO SPFX
SASS COMPILATION IN SPFX
COMPILE SASS
AUTOPREFIX
POSTFIX / TS Class Compilation
AUTOPREFIXING –WHAT IS IT?
.round {
/* Safari 3-4, iOS 1-3.2, Android 1.6- */
-webkit-border-radius: 12px;
/* Firefox 1-3.6 */
-moz-border-radius: 12px;
/* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android
2.1+ */
border-radius: 12px;
}
AUTOPREFIXING –WHAT IS IT?
.round {
border-radius: 12px;
}
AUTOPREFIXING –WHAT IS IT?
.round {
/* Safari 3-4, iOS 1-3.2, Android 1.6- */
-webkit-border-radius: 12px;
/* Firefox 1-3.6 */
-moz-border-radius: 12px;
/* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android
2.1+ */
border-radius: 12px;
}
HOW DOES AUTOPREFIXINGWORK?
1. Lookup attributes on caniuse.com
2. Checks prefixes needed
3. Adds it to CSS
BENEFIT – AUTOPREFIXING
Cleaner CSS / Less Headache
Configured to support Office 365 /
SharePoint optimal
No legacy code removal
SASS COMPILATION IN SPFX
COMPILE SASS
AUTOPREFIX
POSTFIX / TS Class Compilation
Create SASSy web parts in SPFx
POSTFIXING – CSS MODULES
.round {
...
}
.round_f6d5fd65{
...
}
BEFOR
E
AFTER
POSTFIXING – CSS MODULES
.round {
...
}
.round_f6d5fd65{
...
}
BEFOR
E
AFTER
Make class name unique
POSTFIXING
•Web Part cannot effect the overall
experience
•Different web parts – same classes not
possible
•Makes it hard to share code across web
parts – even in same project
TYPESCRIPT CLASS COMPILATION
•Each CSS class 
style.YourClassName
•CSS becomes somewhat type safe
LIMITATION:
invalid class name – .card-hover
JS doesn’t allow dashes in variable names
TYPESCRIPT CLASS COMPILATION
Typescript class = JSON Object
var styles = {
'my-class': 'my-class_2023f0bf’
}
style.my-class //Fails
style[‘my-class’] // CORRECT but not type safe
A CLOSER LOOK IN SPFX
RESULT OF SASS IN SPFX
1. /src/**/mysass.module.scss – source file
2. /lib/**/mysass.module.css – compiled CSS
/lib/**/mysass.module.scss.d.ts – type definition
/lib/**/mysass.module.scss.js – style object
/lib/**/mysass.module.scss.js.map – debug map
AVOID CSS CLASS NAME RENAME
:global – pseudo selector
.ECS2018 {
:global { // Everything in here won’t be replace
@include card-hoverup("green", green,
white, 0.6);
}
}
WHENTO USE GLOBAL?
•Good option for external CSS
•Use it wisely
•Use it inside the container only
DEMO
THEMEDWEB PARTS
•Office UI Fabric supports theming
•Use variable colors
•Use color variables
"[theme:themePrimary, default:#0078d7]"
Create SASSy web parts in SPFx
thank you
questions?
HTTPS://N8D.AT/BLOG@STFBAUER
n8d.at/blog
@StfBauer
Information Architect
Vienna / Austria

More Related Content

PDF
Create SASSY Web Parts - SPSMilan
PPT
SharePoint 2010 branding
PDF
Sass - Getting Started with Sass!
PPTX
SASS - CSS with Superpower
PPTX
Syntactically awesome stylesheets (Sass)
PPTX
Write LESS. DO more.
PPT
An Introduction to CSS Preprocessors (SASS & LESS)
PPTX
SASS - Syntactically Awesome Stylesheet
Create SASSY Web Parts - SPSMilan
SharePoint 2010 branding
Sass - Getting Started with Sass!
SASS - CSS with Superpower
Syntactically awesome stylesheets (Sass)
Write LESS. DO more.
An Introduction to CSS Preprocessors (SASS & LESS)
SASS - Syntactically Awesome Stylesheet

What's hot (20)

PPTX
Less presentation
PDF
LESS CSS
PPT
PPT
CSS Preprocessors: LESS is more or look SASS-y trying
PPTX
Introduction to SASS
PPTX
Start using less css
PPTX
Spsbe using js-linkanddisplaytemplates
PPTX
Introduction to sass
PDF
How to Prepare a WordPress Theme for Public Release
PPTX
Sitecore Experience Accelerator (SxA)
PDF
CSS Workflow. Pre & Post
PPTX
.Less - CSS done right
PDF
Compass n Sass
PPTX
Using js link and display templates
PDF
The WordPress Way
PDF
Dangerous CSS
PPTX
Beautifying senc
PDF
Getting SASSy with front end development
PPTX
SUGUK Cambridge - Display Templates & JSLink for IT Pros
PPTX
HTML/CSS for WordPress
Less presentation
LESS CSS
CSS Preprocessors: LESS is more or look SASS-y trying
Introduction to SASS
Start using less css
Spsbe using js-linkanddisplaytemplates
Introduction to sass
How to Prepare a WordPress Theme for Public Release
Sitecore Experience Accelerator (SxA)
CSS Workflow. Pre & Post
.Less - CSS done right
Compass n Sass
Using js link and display templates
The WordPress Way
Dangerous CSS
Beautifying senc
Getting SASSy with front end development
SUGUK Cambridge - Display Templates & JSLink for IT Pros
HTML/CSS for WordPress
Ad

Similar to Create SASSy web parts in SPFx (20)

PPTX
Stop your share point css become a di-sass-ter today - SPS Munich
PPTX
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
PDF
From CSS to Sass in WordPress
PDF
European SharePoint Webinar - Make SharePoint Sassy
PPT
CSS előfeldolgozók
PPTX
SASS is more than LESS
PDF
Death of a Themer
PDF
CSS framework By Palash
PPTX
SCSS Implementation
PDF
SASS, Compass, Gulp, Greensock
PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
PPT
UNIT 3.ppt
PPTX
Introducing grunt, npm and sass
PPTX
Bliblidotcom - SASS Introduction
PPTX
Joes sass presentation
PPTX
Stop your sharepoint css becoming a disasster today spsbe2015
PPTX
SPS Belgium - Stop your SharePoint CSS becoming a di-SASS-ter today!
PPTX
Post css - Getting start with PostCSS
PPTX
Branding SharePoint from Prototype to Deployment - Workshop
Stop your share point css become a di-sass-ter today - SPS Munich
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
From CSS to Sass in WordPress
European SharePoint Webinar - Make SharePoint Sassy
CSS előfeldolgozók
SASS is more than LESS
Death of a Themer
CSS framework By Palash
SCSS Implementation
SASS, Compass, Gulp, Greensock
Structuring your CSS for maintainability: rules and guile lines to write CSS
UNIT 3.ppt
Introducing grunt, npm and sass
Bliblidotcom - SASS Introduction
Joes sass presentation
Stop your sharepoint css becoming a disasster today spsbe2015
SPS Belgium - Stop your SharePoint CSS becoming a di-SASS-ter today!
Post css - Getting start with PostCSS
Branding SharePoint from Prototype to Deployment - Workshop
Ad

More from Stefan Bauer (7)

PPTX
SPS Brussels 2016 - From design to a modern style guide branding strategies...
PPTX
SPS Barcelona 2016 - Branding Strategies for SharePoint and Add-ins - From De...
PPTX
SharePoint Saturday Stockholm - Branding Strategies for SharePoint and Add-in...
PDF
Branding Deployment in Office 365 and SharePoint 2013/2016
PDF
From Design to a modern Style Guide
PDF
Responsive Web Design and SharePoint
PDF
Responsive vs Adaptive Web Design - What about Device Channels?
SPS Brussels 2016 - From design to a modern style guide branding strategies...
SPS Barcelona 2016 - Branding Strategies for SharePoint and Add-ins - From De...
SharePoint Saturday Stockholm - Branding Strategies for SharePoint and Add-in...
Branding Deployment in Office 365 and SharePoint 2013/2016
From Design to a modern Style Guide
Responsive Web Design and SharePoint
Responsive vs Adaptive Web Design - What about Device Channels?

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Approach and Philosophy of On baking technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Approach and Philosophy of On baking technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding

Create SASSy web parts in SPFx