SlideShare a Scribd company logo
1 of 29
Download to read offline
front-end methodologies
by @ArashManteghi
#coderconf
“There are only two hard things in Computer Science: cache invalidation and naming things.” ~ Phil Karlton
http://arashm.net
@arashmanteghi#coderconf
Introduction Common Solutions Necessity
MaintainableCSS SMACSS ITCSS
OOCSS BEM CSS Modules
Conclusion
@arashmanteghi#coderconf
Introduction
Problems
There are several things that bother us in CSS
The most common annoyances we have are:
• repeating common code
• browser prefixes
• lack of comments
• over qualified selectors
• poor class names
Goal: readable, reusable and maintainable code
Introduction
Common Solutions
Split a large stylesheet into multiple smaller pieces
/stylesheet
style.css
/stylesheets
reset.css
scaffolding.css
layout.css
typography.css
/components
nav-bar.css
search-bar.css
signup-form.css
@arashmanteghi#coderconf
Introduction
Common Solutions
Better variable organization
/* Background Colors */
$background:
$header-background:
$content-background:
/* Colors */
$heading-color:
$link-color:
/* Sizes */
$header-height:
$footer-height:
/* use variable */
a {color: $link-color}
/* Background Colors */
$color-bg:
$color-bg-header:
$color-bg-content:
/* Colors */
$color-heading:
$color-link:
/* Sizes */
$height-header:
$height-footer:
/* use variable */
a {color: $color-link}
/* Colors */
$colors = (
bg: value,
bg-header: value,
bg-content: value,
heading: value,
link: value
);
/* use variable */
a {color: map-get($colors,link)}
@arashmanteghi#coderconf
Introduction
Common Solutions
Order your CSS properties
39%
45%
2%
14%
@arashmanteghi#coderconf
Random
Grouped by type
By line length
Alphabetical
0 12.5 25 37.5 50
39%
45%
2%
14%
Necessity
Should I use it?
typeface
colors
images/icons
composition
“We’re not designing pages, we’re designing systems of
components” ~ Stephen Hay
@arashmanteghi#coderconf
MaintanableCSS
Semantics
<!-- Bad -->
<div class=“red pull-left”>
<div class=“grid row”>
<div class=“col-xs-4”>
Name something based on what it is, not how it looks or behaves
<!-- Good -->
<div class=“header”>
<div class=“basket”>
<div class=“product”>
<div class=“searchResults”>
It’s not clear at all what this HTML
represents.
Here I know exactly what I am looking
at. I know the intention of what this
HTML represents.
So why else should we use semantic class names?
Because it’s easier to understand.
We are building responsive websites.
Semantic class names are easier to find.
The standards recommend it.
@arashmanteghi#coderconf
Reuse
MaintanableCSS
Don’t try and reuse styles
Submit Delete!
.SubmitButton { /* common styles */ }
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
<button class=“SubmitButton SubmitButton-normal”> Submit </button>
<button class=“SubmitButton SubmitButton-danger”> Delete! </button>
@arashmanteghi#coderconf
Reuse
MaintanableCSS
Submit Delete!
.SubmitButton { /* common styles */ }
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
<button class=“SubmitButton-normal"> Submit </button>
<button class=“SubmitButton-danger”> Delete! </button>
Submit Delete!
.button { /* common styles */ }
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
<button class=“SubmitButton-normal”> Submit </button>
<button class=“SubmitButton-danger”> Delete! </button>
@arashmanteghi#coderconf
Reuse
MaintanableCSS
Submit Delete!
.SubmitButton { /* common styles */ }
.SubmitButton-normal { @extend .SubmitButton; /* blue colors */ }
.SubmitButton-danger { @extend .SubmitButton; /* red colors */ }
<button class=“SubmitButton-normal”> Submit </button>
<button class=“SubmitButton-danger”> Delete! </button>
Reuse causes bloat. Reuse breaks semantics. But using preprocessors can help us.
.SubmitButton, .SubmitButton-normal, .SubmitButton-danger {
/* common styles */
}
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
What about Mixins? They can be useful too, but should be designed with caution.
@arashmanteghi#coderconf
Conventions
MaintanableCSS
Conventions can be a bone of contention amongst engineers, but what matters
most is readability and consistency.
/* Square brackets denote optional parts */
.<moduleName>[—<componentName>]—[<state>] { }
/* module container/root */
.searchResults {}
/* components of a module */
.searchResults-heading {}
.searchResults-item {}
/* state: such as AJAX loading */
.searchResults-isLoading {}
@arashmanteghi#coderconf
Modifiers are similar to states in that they can change or override the style of a
module.
SMACSS
What is SMACCS
@arashmanteghi#coderconf
SMACSS is more style guide than rigid framework
Every project needs some organization. There are five types of categories:
• Base
• Layout
• Module
• State
• Theme
Each category has certain guidelines that apply to it.
ITCSS
Manage Large CSS Projects
@arashmanteghi#coderconf
Settings
Tools
Generic
Elements
Objects
Components
Trumps
Each layer contains a series of partials. Recommend naming convention is:
_<layer>.<partial>.scss
For example: _settings.colors.scss , _elements.headings.scss , _components.tabs.scss
ITCSS
Final Result
@arashmanteghi#coderconf
@import “settings.global”;
@import “settings.colors”;
@import “tools.functions”;
@import “tools.mixins”;
@import “generic.box-sizing”;
@import “generic.normalize”;
@import “elements.headings”;
@import “elements.links”;
@import “objects.wrappers”;
@import “objects.grid”;
@import “components.site-nav”;
@import “components.buttons”;
@import “trumps.clearfix”;
@import “trumps.utilities”;
@import “trumps.ie8”;
OOCSS
The Principles of OOCSS
@arashmanteghi#coderconf
An approach for writing CSS that’s reusable, maintainable, and standards-based.
Separate structure and skin Separate container and content
Separate Structure and Skin
@arashmanteghi#coderconf
OOCSS
/* A simple, design-free button object. Extend this object with a
`.btn --*` skin class. */
.btn {
display: inline-block;
padding: 1em 2em;
vertical-align: middle;
}
/* Positive buttons skin. Extends `.btn`. */
.btn --positive {
background: green;
color: white;
}
/* Negative buttons skin. Extends `.btn`. */
.btn --negative {
background: red;
color: white;
}
<button class="btn btn --positive">OK </button>
BEM
Block, Element, Modifier
@arashmanteghi#coderconf
A popular naming convention for classes in HTML and CSS
• Block is a top-level abstraction of a new component, for example a button.
• Elements, can be placed inside and these are denoted by two underscores following
the name of the block
• Modifiers can manipulate the block and Elements.
.dog { /* some styles… */}
.dog__tail { /* some styles… */ }
.dog --small { /* some styles… */ }
@arashmanteghi#coderconf
BEM
Block, Element, Modifier
/* Block component */
.btn {}
/* Element that depends upon the block */
.btn__price {}
/* Modifier that changes the style of the block */
.btn --success {}
.btn --info {}
/* Block component */
.btn {
/* Element that depends upon the block */
&__price {}
/* Modifier that changes the style of the block */
& --success {}
& --info {}
}
CSS Modules
What are CSS Modules
@arashmanteghi#coderconf
CSS files in which all class names and animation names are scoped locally by default.
import styles from “./styles.css”;
element.innerHTML = ‘<h1 class=“{styles.title}”>
An example heading
</h1>’;
._styles__title_309571057 {
background-color: red;
}
<h1 class=“_styles__title_309571057”>
An example heading
</h1>
On the other hand, it is still possible to define global classes (with :global()) such as
helpers
How It Works
@arashmanteghi#coderconf
CSS Modules
{
test: /.css/,
loader: ExtractTextPlugin.extract(‘css?modules
&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]’)
}
with the help of Webpack or Browserify
var browserify = require('browserify')();
browserify.add('./main.js');
browserify.plugin(require('css-modulesify'), {
rootDir: __dirname,
output: './path/to/my.css'
});
browserify.bundle();
bit.ly/css--modules
@arashmanteghi#coderconf
React + CSS Modules
CSS Modules
import React from 'react';
import styles from './table.css';
export default class Table extends React.Component {
render () {
return ( <div className=“{styles.table}”>
<div className=“{styles.row}”>
<div className=“{styles.cell}”> A0 </div>
<div className=“{styles.cell}”> B0 </div>
</div>
</div> );
}
}
We want to create DOM easily
<div class=“table__table___32osj”>
<div class=“table__row___2w27N”>
<div class=“table__cell___2w27N”>A0 </div>
<div class=“table__cell___1oVw5”>B0 </div>
</div>
</div>
Extend Problem
@arashmanteghi#coderconf
Submit Delete!
.SubmitButton { /* common styles */ }
.SubmitButton-normal { @extend .SubmitButton; /* blue colors */ }
.SubmitButton-danger { @extend .SubmitButton; /* red colors */ }
<button class=“SubmitButton SubmitButton-normal”> Submit </button>
<button class=“SubmitButton SubmitButton-danger”> Delete! </button>
.SubmitButton, .SubmitButton-normal, .SubmitButton-danger {
/* common styles */
}
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
CSS Modules
Extend Problem
@arashmanteghi#coderconf
.SubmitButton { /* common styles */ }
.SubmitButton-normal { @extend .SubmitButton; /* blue colors */ }
.SubmitButton-danger { @extend .SubmitButton; /* red colors */ }
.SubmitButton-v { @extend .SubmitButton; /* other styles */ }
.SubmitButton-w { @extend .SubmitButton; /* other styles */ }
.SubmitButton-x { @extend .SubmitButton; /* other styles */ }
.SubmitButton-y { @extend .SubmitButton; /* other styles */ }
.SubmitButton-z { @extend .SubmitButton; /* other styles */ }
.SubmitButton, .SubmitButton-normal, .SubmitButton-
danger, .SubmitButton-v, .SubmitButton-w. .SubmitButton-
x, .SubmitButton-y, .SubmitButton-z, { /* common styles */ }
.SubmitButton-normal { /* blue colors */ }
.SubmitButton-danger { /* red colors */ }
.‌‌.‌.
.‌‌.‌.‌
CSS Modules
The Composes Keyword
@arashmanteghi#coderconf
.base { /* common styles */ }
.normal {
composes: base;
color: hsl(210, 61%, 31%);
background: hsla(210,61%,51%,0.1);
}
.danger {
composes: base;
color: hsla(0, 61%, 51%, 0.5);
background: white;
}
<button className=“{styles.danger}”>Delete! </button>
<button class=“base_81f12d56 danger_b7d2ad6f”>Delete! </button>
CSS Modules
The Composes Keyword
@arashmanteghi#coderconf
/* colors.css */
.blue {
color: hsl(210, 61%, 31%);
}
.light-blue-bg {
background: hsla(210,61%,51%,0.1);
}
.base { /* common styles */ }
.normal {
composes: base;
composes: blue light-blue-bg from “./colors.css”;
}
<button className=“{style.normal}”>Delete! </button>
CSS Modules
The Composes Keyword
@arashmanteghi#coderconf
.blue_c22950a8 { color: hsl(210, 61%, 31%); }
.light-blue-bg_ea7f0091 { background: hsla(210,61%,51%,0.1); }
.base_81f12d56 { /* common styles */ }
.normal_f34f7fa0 {}
<button class=“base_81f12d56
blue_c22950a8
light-blue-bg_ea7f0091
normal_f34f7fa0”>
Submit
</button>
CSS Modules
Conclusion
@arashmanteghi#coderconf
Ask ten experts, and you’ll receive ten different answers, but there are many more.
Which one is the best?
Thanks :)
@arashmanteghi#coderconf
Any Questions?

More Related Content

What's hot

The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...Nicole Sullivan
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic templatevathur
 
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopShay Howe
 
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)Clément Wehrung
 
HTML Foundations, pt 2
HTML Foundations, pt 2HTML Foundations, pt 2
HTML Foundations, pt 2Shawn Calvert
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Marakana Inc.
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5Robert Nyman
 

What's hot (15)

Os Harris
Os HarrisOs Harris
Os Harris
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
HTML5 Essentials
HTML5 EssentialsHTML5 Essentials
HTML5 Essentials
 
Bootstrap 4 ppt
Bootstrap 4 pptBootstrap 4 ppt
Bootstrap 4 ppt
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
Html tag list
Html tag listHtml tag list
Html tag list
 
Html 5 tags
Html  5 tagsHtml  5 tags
Html 5 tags
 
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
 
Java script
Java scriptJava script
Java script
 
Html bangla
Html banglaHtml bangla
Html bangla
 
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
ePub 3, HTML 5 & CSS 3 (+ Fixed-Layout)
 
HTML Foundations, pt 2
HTML Foundations, pt 2HTML Foundations, pt 2
HTML Foundations, pt 2
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5
 

Viewers also liked

Mavi kod ss
Mavi kod ssMavi kod ss
Mavi kod sstyfngnc
 
Programação do iii fórum do hospital regional
Programação do iii fórum do hospital regionalProgramação do iii fórum do hospital regional
Programação do iii fórum do hospital regionalJosete Sampaio
 
Dylan Cromhout_TDP Portfolio (01-10-13)
Dylan Cromhout_TDP Portfolio (01-10-13)Dylan Cromhout_TDP Portfolio (01-10-13)
Dylan Cromhout_TDP Portfolio (01-10-13)Dylan Cromhout
 
Câmara temática de defesa dos direitos da mulher 1
Câmara temática de defesa dos direitos da mulher 1Câmara temática de defesa dos direitos da mulher 1
Câmara temática de defesa dos direitos da mulher 1Josete Sampaio
 

Viewers also liked (8)

Mavi kod ss
Mavi kod ssMavi kod ss
Mavi kod ss
 
Programação do iii fórum do hospital regional
Programação do iii fórum do hospital regionalProgramação do iii fórum do hospital regional
Programação do iii fórum do hospital regional
 
Dylan Cromhout_TDP Portfolio (01-10-13)
Dylan Cromhout_TDP Portfolio (01-10-13)Dylan Cromhout_TDP Portfolio (01-10-13)
Dylan Cromhout_TDP Portfolio (01-10-13)
 
Tipos de investigación
Tipos de investigaciónTipos de investigación
Tipos de investigación
 
Câmara temática de defesa dos direitos da mulher 1
Câmara temática de defesa dos direitos da mulher 1Câmara temática de defesa dos direitos da mulher 1
Câmara temática de defesa dos direitos da mulher 1
 
Sp Presentation
Sp PresentationSp Presentation
Sp Presentation
 
S4 TAREA4 SAMOY
S4 TAREA4 SAMOYS4 TAREA4 SAMOY
S4 TAREA4 SAMOY
 
Kurita Company Profile
Kurita Company ProfileKurita Company Profile
Kurita Company Profile
 

Similar to Front-End Methodologies

Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
CSS Frameworks
CSS FrameworksCSS Frameworks
CSS FrameworksMike Crabb
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Gheyath M. Othman
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Automated Tests and CSS
Automated Tests and CSSAutomated Tests and CSS
Automated Tests and CSSklamping
 
CSS framework By Palash
CSS framework By PalashCSS framework By Palash
CSS framework By PalashPalashBajpai
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Erin M. Kidwell
 
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignCSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignKate Travers
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS MethodologyZohar Arad
 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Designmlincol2
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptraghavanp4
 
Learn CSS From Scratch
Learn CSS From ScratchLearn CSS From Scratch
Learn CSS From Scratchecobold
 

Similar to Front-End Methodologies (20)

Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
CSS Frameworks
CSS FrameworksCSS Frameworks
CSS Frameworks
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Automated Tests and CSS
Automated Tests and CSSAutomated Tests and CSS
Automated Tests and CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
CSS framework By Palash
CSS framework By PalashCSS framework By Palash
CSS framework By Palash
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Create a landing page
Create a landing pageCreate a landing page
Create a landing page
 
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented DesignCSMess to OOCSS: Refactoring CSS with Object Oriented Design
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
HTML & CSS 2017
HTML & CSS 2017HTML & CSS 2017
HTML & CSS 2017
 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Design
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
Learn CSS From Scratch
Learn CSS From ScratchLearn CSS From Scratch
Learn CSS From Scratch
 

Recently uploaded

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Front-End Methodologies

  • 1. front-end methodologies by @ArashManteghi #coderconf “There are only two hard things in Computer Science: cache invalidation and naming things.” ~ Phil Karlton http://arashm.net
  • 2. @arashmanteghi#coderconf Introduction Common Solutions Necessity MaintainableCSS SMACSS ITCSS OOCSS BEM CSS Modules Conclusion
  • 3. @arashmanteghi#coderconf Introduction Problems There are several things that bother us in CSS The most common annoyances we have are: • repeating common code • browser prefixes • lack of comments • over qualified selectors • poor class names Goal: readable, reusable and maintainable code
  • 4. Introduction Common Solutions Split a large stylesheet into multiple smaller pieces /stylesheet style.css /stylesheets reset.css scaffolding.css layout.css typography.css /components nav-bar.css search-bar.css signup-form.css @arashmanteghi#coderconf
  • 5. Introduction Common Solutions Better variable organization /* Background Colors */ $background: $header-background: $content-background: /* Colors */ $heading-color: $link-color: /* Sizes */ $header-height: $footer-height: /* use variable */ a {color: $link-color} /* Background Colors */ $color-bg: $color-bg-header: $color-bg-content: /* Colors */ $color-heading: $color-link: /* Sizes */ $height-header: $height-footer: /* use variable */ a {color: $color-link} /* Colors */ $colors = ( bg: value, bg-header: value, bg-content: value, heading: value, link: value ); /* use variable */ a {color: map-get($colors,link)} @arashmanteghi#coderconf
  • 6. Introduction Common Solutions Order your CSS properties 39% 45% 2% 14% @arashmanteghi#coderconf Random Grouped by type By line length Alphabetical 0 12.5 25 37.5 50 39% 45% 2% 14%
  • 7. Necessity Should I use it? typeface colors images/icons composition “We’re not designing pages, we’re designing systems of components” ~ Stephen Hay @arashmanteghi#coderconf
  • 8. MaintanableCSS Semantics <!-- Bad --> <div class=“red pull-left”> <div class=“grid row”> <div class=“col-xs-4”> Name something based on what it is, not how it looks or behaves <!-- Good --> <div class=“header”> <div class=“basket”> <div class=“product”> <div class=“searchResults”> It’s not clear at all what this HTML represents. Here I know exactly what I am looking at. I know the intention of what this HTML represents. So why else should we use semantic class names? Because it’s easier to understand. We are building responsive websites. Semantic class names are easier to find. The standards recommend it. @arashmanteghi#coderconf
  • 9. Reuse MaintanableCSS Don’t try and reuse styles Submit Delete! .SubmitButton { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } <button class=“SubmitButton SubmitButton-normal”> Submit </button> <button class=“SubmitButton SubmitButton-danger”> Delete! </button> @arashmanteghi#coderconf
  • 10. Reuse MaintanableCSS Submit Delete! .SubmitButton { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } <button class=“SubmitButton-normal"> Submit </button> <button class=“SubmitButton-danger”> Delete! </button> Submit Delete! .button { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } <button class=“SubmitButton-normal”> Submit </button> <button class=“SubmitButton-danger”> Delete! </button> @arashmanteghi#coderconf
  • 11. Reuse MaintanableCSS Submit Delete! .SubmitButton { /* common styles */ } .SubmitButton-normal { @extend .SubmitButton; /* blue colors */ } .SubmitButton-danger { @extend .SubmitButton; /* red colors */ } <button class=“SubmitButton-normal”> Submit </button> <button class=“SubmitButton-danger”> Delete! </button> Reuse causes bloat. Reuse breaks semantics. But using preprocessors can help us. .SubmitButton, .SubmitButton-normal, .SubmitButton-danger { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } What about Mixins? They can be useful too, but should be designed with caution. @arashmanteghi#coderconf
  • 12. Conventions MaintanableCSS Conventions can be a bone of contention amongst engineers, but what matters most is readability and consistency. /* Square brackets denote optional parts */ .<moduleName>[—<componentName>]—[<state>] { } /* module container/root */ .searchResults {} /* components of a module */ .searchResults-heading {} .searchResults-item {} /* state: such as AJAX loading */ .searchResults-isLoading {} @arashmanteghi#coderconf Modifiers are similar to states in that they can change or override the style of a module.
  • 13. SMACSS What is SMACCS @arashmanteghi#coderconf SMACSS is more style guide than rigid framework Every project needs some organization. There are five types of categories: • Base • Layout • Module • State • Theme Each category has certain guidelines that apply to it.
  • 14. ITCSS Manage Large CSS Projects @arashmanteghi#coderconf Settings Tools Generic Elements Objects Components Trumps Each layer contains a series of partials. Recommend naming convention is: _<layer>.<partial>.scss For example: _settings.colors.scss , _elements.headings.scss , _components.tabs.scss
  • 15. ITCSS Final Result @arashmanteghi#coderconf @import “settings.global”; @import “settings.colors”; @import “tools.functions”; @import “tools.mixins”; @import “generic.box-sizing”; @import “generic.normalize”; @import “elements.headings”; @import “elements.links”; @import “objects.wrappers”; @import “objects.grid”; @import “components.site-nav”; @import “components.buttons”; @import “trumps.clearfix”; @import “trumps.utilities”; @import “trumps.ie8”;
  • 16. OOCSS The Principles of OOCSS @arashmanteghi#coderconf An approach for writing CSS that’s reusable, maintainable, and standards-based. Separate structure and skin Separate container and content
  • 17. Separate Structure and Skin @arashmanteghi#coderconf OOCSS /* A simple, design-free button object. Extend this object with a `.btn --*` skin class. */ .btn { display: inline-block; padding: 1em 2em; vertical-align: middle; } /* Positive buttons skin. Extends `.btn`. */ .btn --positive { background: green; color: white; } /* Negative buttons skin. Extends `.btn`. */ .btn --negative { background: red; color: white; } <button class="btn btn --positive">OK </button>
  • 18. BEM Block, Element, Modifier @arashmanteghi#coderconf A popular naming convention for classes in HTML and CSS • Block is a top-level abstraction of a new component, for example a button. • Elements, can be placed inside and these are denoted by two underscores following the name of the block • Modifiers can manipulate the block and Elements. .dog { /* some styles… */} .dog__tail { /* some styles… */ } .dog --small { /* some styles… */ }
  • 19. @arashmanteghi#coderconf BEM Block, Element, Modifier /* Block component */ .btn {} /* Element that depends upon the block */ .btn__price {} /* Modifier that changes the style of the block */ .btn --success {} .btn --info {} /* Block component */ .btn { /* Element that depends upon the block */ &__price {} /* Modifier that changes the style of the block */ & --success {} & --info {} }
  • 20. CSS Modules What are CSS Modules @arashmanteghi#coderconf CSS files in which all class names and animation names are scoped locally by default. import styles from “./styles.css”; element.innerHTML = ‘<h1 class=“{styles.title}”> An example heading </h1>’; ._styles__title_309571057 { background-color: red; } <h1 class=“_styles__title_309571057”> An example heading </h1> On the other hand, it is still possible to define global classes (with :global()) such as helpers
  • 21. How It Works @arashmanteghi#coderconf CSS Modules { test: /.css/, loader: ExtractTextPlugin.extract(‘css?modules &importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]’) } with the help of Webpack or Browserify var browserify = require('browserify')(); browserify.add('./main.js'); browserify.plugin(require('css-modulesify'), { rootDir: __dirname, output: './path/to/my.css' }); browserify.bundle(); bit.ly/css--modules
  • 22. @arashmanteghi#coderconf React + CSS Modules CSS Modules import React from 'react'; import styles from './table.css'; export default class Table extends React.Component { render () { return ( <div className=“{styles.table}”> <div className=“{styles.row}”> <div className=“{styles.cell}”> A0 </div> <div className=“{styles.cell}”> B0 </div> </div> </div> ); } } We want to create DOM easily <div class=“table__table___32osj”> <div class=“table__row___2w27N”> <div class=“table__cell___2w27N”>A0 </div> <div class=“table__cell___1oVw5”>B0 </div> </div> </div>
  • 23. Extend Problem @arashmanteghi#coderconf Submit Delete! .SubmitButton { /* common styles */ } .SubmitButton-normal { @extend .SubmitButton; /* blue colors */ } .SubmitButton-danger { @extend .SubmitButton; /* red colors */ } <button class=“SubmitButton SubmitButton-normal”> Submit </button> <button class=“SubmitButton SubmitButton-danger”> Delete! </button> .SubmitButton, .SubmitButton-normal, .SubmitButton-danger { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } CSS Modules
  • 24. Extend Problem @arashmanteghi#coderconf .SubmitButton { /* common styles */ } .SubmitButton-normal { @extend .SubmitButton; /* blue colors */ } .SubmitButton-danger { @extend .SubmitButton; /* red colors */ } .SubmitButton-v { @extend .SubmitButton; /* other styles */ } .SubmitButton-w { @extend .SubmitButton; /* other styles */ } .SubmitButton-x { @extend .SubmitButton; /* other styles */ } .SubmitButton-y { @extend .SubmitButton; /* other styles */ } .SubmitButton-z { @extend .SubmitButton; /* other styles */ } .SubmitButton, .SubmitButton-normal, .SubmitButton- danger, .SubmitButton-v, .SubmitButton-w. .SubmitButton- x, .SubmitButton-y, .SubmitButton-z, { /* common styles */ } .SubmitButton-normal { /* blue colors */ } .SubmitButton-danger { /* red colors */ } .‌‌.‌. .‌‌.‌.‌ CSS Modules
  • 25. The Composes Keyword @arashmanteghi#coderconf .base { /* common styles */ } .normal { composes: base; color: hsl(210, 61%, 31%); background: hsla(210,61%,51%,0.1); } .danger { composes: base; color: hsla(0, 61%, 51%, 0.5); background: white; } <button className=“{styles.danger}”>Delete! </button> <button class=“base_81f12d56 danger_b7d2ad6f”>Delete! </button> CSS Modules
  • 26. The Composes Keyword @arashmanteghi#coderconf /* colors.css */ .blue { color: hsl(210, 61%, 31%); } .light-blue-bg { background: hsla(210,61%,51%,0.1); } .base { /* common styles */ } .normal { composes: base; composes: blue light-blue-bg from “./colors.css”; } <button className=“{style.normal}”>Delete! </button> CSS Modules
  • 27. The Composes Keyword @arashmanteghi#coderconf .blue_c22950a8 { color: hsl(210, 61%, 31%); } .light-blue-bg_ea7f0091 { background: hsla(210,61%,51%,0.1); } .base_81f12d56 { /* common styles */ } .normal_f34f7fa0 {} <button class=“base_81f12d56 blue_c22950a8 light-blue-bg_ea7f0091 normal_f34f7fa0”> Submit </button> CSS Modules
  • 28. Conclusion @arashmanteghi#coderconf Ask ten experts, and you’ll receive ten different answers, but there are many more. Which one is the best?