SlideShare a Scribd company logo
Modular Stylesheets with Css Modules (Dublin CSS)
Writing Modular Stylesheets
With CSS Modules
www.katiefenn.co.uk/scotland-css-2016/
Why?
www.katiefenn.co.uk/scotland-css-2016/
www.katiefenn.co.uk/scotland-css-2016/ NASA / Apollo 17 Crew
Global
Scope
www.katiefenn.co.uk/scotland-css-2016/ https://flic.kr/p/9DWnML
CSS is
brittle
www.katiefenn.co.uk/scotland-css-2016/ https://flic.kr/p/9Rcgca
Lack of
modularity
@Katie_Fenn
@Katie_Fenn
@Katie_Fenn https://flic.kr/p/BF3Z64
www.katiefenn.co.uk/scotland-css-2016/ https://flic.kr/p/qP5LWy
Plugins
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Unique Classes
/* Source file */
.input {
height: 30px;
}
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Unique Classes
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Unique Classes
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Unique Classes
/* Processed file */
._input_lg8gg_6 {
height: 30px;
}
lg8gg_6
The plugin makes
classes unique
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Unique Classes
.Registration__Input_Text
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Global Classes
/* Source file */
:global .background {
color: white;
font-family: Arial;
}
:global
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Global Classes
/* Source file */
:global .background {
color: white;
font-family: Arial;
}
:global
:global makes classes
work normally
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Global Classes
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Global Classes
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Global Classes
/* Processed file */
.background {
color: white;
font-family: Arial;
}
www.katiefenn.co.uk/scotland-css-2016/
.background
:global makes CSS
work normally
#DZY
Map File
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Map File
/* json map file */
{
"input":"_input_lg8gg_6",
}
_input_lg8gg_6input
Maps unique classes…
…back to the original
www.katiefenn.co.uk/scotland-css-2016/ #DZY
var styles = require('./TextField.styles.css');
var TextField = React.createClass({
render() {
return (
<div>
<input
className={ styles.input } />
</div>)
;
}
});
var styles = require('./TextField.styles.css');
class TextField extends React.Component {
render() {
return (
<div>
<input
className={ styles.input } />
</div>)
;
}
}
Unique Classes
www.katiefenn.co.uk/lead-dev-2016/
var styles = require('./TextField.styles.css');
var TextField = React.createClass({
render() {
return (
<div>
<input
className={ styles.input } />
</div>)
;
}
});
var styles = require('./TextField.styles.css');
class TextField extends React.Component {
render() {
return (
<div>
<input
className={ styles.input } />
</div>)
;
}
}
Load classes from map file…
…to inject unique classes
into templates
Unique Classes
www.katiefenn.co.uk/lead-dev-2016/
Composable Styles
/* Source file */
.input {
composes:
shared from “../shared.css”
}
composes:
shared from “../shared.css”
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Composable Styles
/* Source file */
.input {
composes:
shared from “../shared.css”
}
composes:
shared from “../shared.css”
www.katiefenn.co.uk/scotland-css-2016/
composes styles
from other rules or modules
#DZY
Composable Styles
composes:
shared from “../shared.css”
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Composable Styles
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Composable Styles
// json map File
{
“input":
"_input_1j141_6 _shared_1g7is_2"
}
_input_1j141_6 _shared_1g7is_2
compose adds the included class…
…anywhere the including
class is used
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Composable Styles
/* Source file */
.input {
composes:
pa1 ma1 black-60 from global;
}
www.katiefenn.co.uk/scotland-css-2016/
compose from global
frameworks like Tachyons
composes:
pa1 ma1 black-60 from global
Asset Management
/* Source file */
.icon {
background: url(./twitter.png);
}
www.katiefenn.co.uk/scotland-css-2016/
url(./twitter.png);
Asset Management
/* Source file */
.icon {
background: url(./twitter.png);
}
www.katiefenn.co.uk/scotland-css-2016/
css modules resolves
paths to images
url(./twitter.png);
Asset Management
www.katiefenn.co.uk/scotland-css-2016/
Asset Management
www.katiefenn.co.uk/scotland-css-2016/
Asset Management
/* Processed file */
.icon {
background:
url(img/fdfc448bda4857.png);
}
www.katiefenn.co.uk/scotland-css-2016/
WebPack
css-loader
github.com/webpack/css-loader
www.katiefenn.co.uk/scotland-css-2016/
PostCSS
postcss-modules
github.com/css-modules/postcss-modules
www.katiefenn.co.uk/scotland-css-2016/
Demo
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
www.katiefenn.co.uk/scotland-css-2016/ #DZY
Try it yourself
https://github.com/katiefenn/php-css-modules-demo
www.katiefenn.co.uk/scotland-css-2016/
Quirks
• No cross-module selectors
• Only id and class selectors
• Composition requires class or id
www.katiefenn.co.uk/scotland-css-2016/
Benefits
Modularity
www.katiefenn.co.uk/scotland-css-2016/
Benefits
Durability
www.katiefenn.co.uk/scotland-css-2016/ https://flic.kr/p/do9JeH
Benefits
Portability
www.katiefenn.co.uk/scotland-css-2016/ https://flic.kr/p/bvc5zB
Alternatives
• Inline styles in React
• Radium
• Aphrodite
• Styled Components 💅
www.katiefenn.co.uk/scotland-css-2016/
“The component is
the unit of re-use”
Glen Mailer
www.katiefenn.co.uk/scotland-css-2016/ https://www.missguided.co.uk
#DZY
Thank You
www.katiefenn.co.uk/scotland-css-2016/
Slides: tiny.cc/s-css-katie
Twitter: @katie_fenn
#DZY
Thank You
www.katiefenn.co.uk/scotland-css-2016/
Slides: tiny.cc/s-css-katie
Twitter: @katie_fenn
#DZY

More Related Content

PDF
Creating WordPress Theme Faster, Smarter & Without Swearing
PDF
Krueger Library Custom CSS for LibGuides
PDF
Sass - Making CSS fun again.
PDF
Magento x codekit x sass x compass x skeleton responsive grid
PPTX
Class15
PDF
Hardboiled Front End Development — Found.ation
PPTX
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
PDF
以Vue開發電子商務網站
架構與眉角
Creating WordPress Theme Faster, Smarter & Without Swearing
Krueger Library Custom CSS for LibGuides
Sass - Making CSS fun again.
Magento x codekit x sass x compass x skeleton responsive grid
Class15
Hardboiled Front End Development — Found.ation
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
以Vue開發電子商務網站
架構與眉角

Similar to Modular Stylesheets with Css Modules (Dublin CSS) (20)

PDF
CSS Introduction
PDF
SCSS Styleguide
PPTX
Branding SharePoint from Prototype to Deployment - Workshop
PPT
Using a CSS Framework
PPTX
Managing responsive websites with css preprocessors.
PDF
1- Learn Flexbox & CSS Grid / Environment setup
PPT
Css Founder.com | Cssfounder Org
PPT
Website designing company | Cssfounder.com
PDF
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
PDF
How to use CSS3 in WordPress
PDF
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
PDF
Advanced css concepts - edukite
PDF
Even faster web sites
PDF
CSS framework By Palash
PDF
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
PDF
Create SASSy web parts in SPFx
PDF
[Bauer] SASSy web parts with SPFX
PDF
CSS Architecture - JSIL.pdf
PDF
Social Connections VI — IBM Connections Extensions and Themes Demystified
PDF
Website Performance Basics
CSS Introduction
SCSS Styleguide
Branding SharePoint from Prototype to Deployment - Workshop
Using a CSS Framework
Managing responsive websites with css preprocessors.
1- Learn Flexbox & CSS Grid / Environment setup
Css Founder.com | Cssfounder Org
Website designing company | Cssfounder.com
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
How to use CSS3 in WordPress
Advanced Front End Architecture in D8: Sass, Gulp, & Living Style Guides
Advanced css concepts - edukite
Even faster web sites
CSS framework By Palash
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
Create SASSy web parts in SPFx
[Bauer] SASSy web parts with SPFX
CSS Architecture - JSIL.pdf
Social Connections VI — IBM Connections Extensions and Themes Demystified
Website Performance Basics
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Spectroscopy.pptx food analysis technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectroscopy.pptx food analysis technology
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Ad

Modular Stylesheets with Css Modules (Dublin CSS)