SlideShare a Scribd company logo
1 of 65
CSS Best Practices, Style
Guide, and Tips
#ITDEVCON
Chris Love
http://love2dev.com
@ChrisLove
Who Am I?
• ASP.NET MVP
• ASP Insider
• MS Edge User Agent
• Author
• Speaker
• Tweaker, Lover of Web, JavaScript, CSS & HTML5
• @ChrisLove
• Love2Dev.com
#ITDEVCON
High Performance Single Page Web Applications
• Responsive Design
• Touch
• Mobile First
• SPA
• Extensible, Scalable Architecture
• Web Build and Workflow
• Goes Really Fast!
• ~395 Pages
• 20 Chapters
• $9.99
#ITDEVCON
Slide Decks & Source Code
• Slide Deck – http://slidesha.re/19NZInK
• Source Code – http://GitHub.com/docluv
#ITDEVCON
CSS
• Language Defining Rendering Rules
#ITDEVCON
CSS
.main-content {
overflow: hidden;
left: 6.3166666%;
right: 0;
top: 50px;
bottom: 4.166666%;
position: absolute;
border-radius: 5px 5px 0 0;
background-color: #000000;
-moz-transition: all 700ms ease-out;
-o-transition: all 700ms ease-out;
-webkit-transition: all 700ms ease-out;
transition: all 700ms ease-out;
}
#ITDEVCON
Selector/Rule
Properties
Vendor Specific
CSS
•Rules
• Defined using selector syntax
•Properties
• The specifics
•Media Queries
• Define Rules Based on Browser & Device Characteristics
#ITDEVCON
CSS Property Units
•px – pixels
•% - percent
•em – relative to the element’s font-size
•rem – Relative to the root element’s font-size
•vh/vw – Viewport Height/Viewport Width
•Any 0 does not require a unit
#ITDEVCON
CSS Selector Syntax
• Element
• H1, DIV, P
• Class
• .btn, . spa-child-view
• ID
• #tryToAvoid
#ITDEVCON
Advanced CSS Selector Syntax
• Nested Selectors
• Allows You To Apply Rules to Children of Matched Elements
• .main-content p
• Be careful to avoid complexity
• Dynamic By Attributes
• script[class='spa-view']
#ITDEVCON
By Attribute/type
input[type="email"] {
color:blue;
}
#ITDEVCON
Starts With
[class^="my-class-"] {
color:red;
}
#ITDEVCON
Ends With
[class$=“-my-class"] {
color:red;
}
#ITDEVCON
Contains
[class*="class"] {
color:red;
}
#ITDEVCON
Customize Social Links
a[href*="twitter.com"] { color:#55acee; }
a[href*="facebook.com"] { color:#3b5998; }
a[href*="google.com"] { color:#db4437; }
#ITDEVCON
Remove webkit Input Border
input[type="text"]:focus { outline: none; }
#ITDEVCON
psuedo-classes
• Define CSS Rules for Element States
• Hover
• Active
• Define Rules for hidden elements
• :before, :after
• Define Rules for nth Element
• :nth-of-type(3n)
Content Property
• Defines ‘text’ value for matched element
• Useful with :before and :after pseudo element
Responsive Table Trick
• Tables Create a Unique Responsive Design Problem
• Change CSS To Change Rendering Rules
• Turn Table into a fake set of DIVs
• Leverage content property to define value labels
• https://css-tricks.com/responsive-data-tables/
#ITDEVCON
Responsive Table Trick
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Job Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>James</td>
<td>Matman</td>
<td>Chief Sandwich Eater</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
<td>Crimefighter Sorta</td>
</tr>
</tbody>
</table>
Responsive Table Trick
@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
table, thead, tbody, th, td, tr {
display: block;
}
}
#ITDEVCON
Responsive Table Trick
td:nth-of-type(1):before { content: "First Name"; }
td:nth-of-type(2):before { content: "Last Name"; }
td:nth-of-type(3):before { content: "Job Title"; }
td:nth-of-type(4):before { content: "Favorite Color"; }
td:nth-of-type(5):before { content: "Wars of Trek?"; }
td:nth-of-type(6):before { content: "Porn Name"; }
td:nth-of-type(7):before { content: "Date of Birth"; }
td:nth-of-type(8):before { content: "Dream Vacation City"; }
td:nth-of-type(9):before { content: "GPA"; }
td:nth-of-type(10):before { content: "Arbitrary Data"; }
CSS Selector Specificity
• Complex Specificity
• .main-content > article #myArticleId p
• Leads to large CSS files
• Makes Code Unmanageable
• Lower the Score the Better
• Browsers Parse Selectors Right to Left
• * Avoid Universal Selector
Right-Left Rule
• .main-content > article #myArticleId p
• Translates to:
• #myArticleId p
• Think More Like the Browser When Defining Selectors
Calculate CSS Specificity
• Count the Inline Style
• count the number of ID selectors in the selector (= a)
• count the number of class selectors, attributes selectors, and pseudo-
classes in the selector (= b)
• count the number of type selectors and pseudo-elements in the
selector (= c)
• ignore the universal selector
Calculate CSS Specificity
http://specificity.keegan.st/
BEM Naming Convention
• Block
• Element
• Modifier
• Bootstrap and Primer Good Examples
BEM Naming Convention
• .btn {…}
• .btn-primary {…}
• .btn-primary:disabled {…}
• .btn-xs {…}
• Might also see __ between words
BEM Naming Convention
• <button type="button" class="btn btn-primary">Primary</button>
• <button type="button" class="btn btn-success">Success</button>
• <button type="button" class="btn btn-info">Info</button>
• <button type="button" class="btn btn-warning">Warning</button>
CSS Cascading
• Last, Most Specific Rule Wins
• Be mindful of your CSS Definition Order
• Overwrites Previously Defined Rules
• Simple rule make this easy to maintain and create
Responsive Design
“this unspoken agreement to pretend that we had a certain size. And that size
changed over the years. For a while, we all sort of tacitly agreed that 640 by 480
was the right size, and then later than changed to 800:600, and 1024; we seem
to have settled on this 960 pixel as being this like, default. It’s still unknown. We
still don’t know the size of the browser; it’s just like this consensual
hallucination that we’ve all agreed to participate in: “Let’s assume the browser
has a browser width of at least 960 pixels.”
Jeremy Keith
bit.ly/1bhH6rw
Responsive Web Design
#ITDEVCON
Responsive Web Design
• Introduced by Ethan Marcotte 2010 -
bit.ly/178an9e
• Web Design Approach To Create An Optimal
Viewing Experience Across All Browser ViewPorts
• Fluid Layouts
• Media Queries
• Minimal if any JavaScript Required
Fluid Layout
• Stretch as the Browser ViewPort Changes
• Browser’s Viewable Area Inside the Chrome
• Serve as the Foundation for the Web Application
Layout
• Great Way To Create Native Like Experience
Fluid Layout
• Leverage Absolute Positioning
• Enables Fixed Positioning Without position:fixed
• Leverage overflow scrolling
Media Queries
@media (min-width: 600px) {
/* Selectors & Rules */
}
@media (min-width: 820px) {
/* Selectors & Rules */
}
@media (min-width: 1080px) {
/* Selectors & Rules */
}
Avoid Embedded Styles
• Don't separate content from design
• Cause more maintenance headaches
• Make your pages larger
• Do not take advantage of Http Caching
• Lead to Duplicate Rules
CSS - Files
• Should
• Use External Files
• Hosted on a CDN
• Bundled & Minified *
• HTTP/2 Changes the Bundling Rule
CSS – Debug Files
• Should
• Use Many Files
• They Should Correlate to a Purpose
• View
• Component
• Layout
CSS –Files
css/
site.min.css
/dev
/libs
/ui
/views
CSS Best Practices
• Link to External Files in the HEAD
• Ensures CSS read before HTML
• Avoid Using @import
• Causes CSS to be Parsed After Document
CSS Reset
• Establishes a Common Base
• Each Browser has a default CSS stylesheet
• Many Resets Availble
• Normalize.css probably most popular
• Popular libraries have resets; ex bootstrap uses normalize
CSS Libraries
• Many Available
• Bootstrap is the current defacto standard
• Primer based on Boostrap
• Created by bootstrap author
• GitHub’s internal library
• https://github.com/primer/primer
CSS Libraries
• Be Careful to not be Completely Dependent on Library
• Understand How CSS Rules, Apply Best Practices
• Build Your Own Custom Version
• Grunt/Gulp
Critical CSS
• The CSS Required to Render The Above the Fold Content
• Embed Inline, in HEAD element
• Instant Render if HTML < 14kb
• Works great for a SPA
• criticalCSS Node Module
• https://www.npmjs.com/package/criticalcss
Critical CSS Grunt
grunt.initConfig({
criticalcss: {
custom: {
options: {
url: "http://localhost:4000",
width: 1200,
height: 900,
outputfile: "dist/critical.css",
filename: "/path/to/local/all.css", // Using path.resolve( path.join( ... ) ) is a good idea here
buffer: 800*1024,
ignoreConsole: false
}
}
},
});
UnCSS Grunt
uncss: {
dist: {
src: ['app/index.html'],
dest: 'app/css/tidy.css',
options: {
report: 'min'
}
}
}
https://www.npmjs.com/package/grunt-uncss
CSS Code Style
• Define Section Titles
/*------------------------------------*
$MAIN
*------------------------------------*/
CSS Rule Formatting
• Use one discrete selector per line in multi-selector rulesets.
• Include a single space before the opening brace of a
ruleset.
• Include one declaration per line in a declaration block.
• Use one level of indentation for each declaration.
• Include a single space after the colon of a declaration.
CSS Rule Formatting
• Use lowercase and shorthand hex values, e.g., `#aaa`.
• Use single or double quotes consistently. Preference is for
double quotes, e.g., `content: ""`.
• Quote attribute values in selectors, e.g.,
`input[type="checkbox"]`.
• _Where allowed_, avoid specifying units for zero-values,
e.g., `margin: 0`.
CSS Rule Formatting
• Include a space after each comma in comma-separated
property or function values.
• Include a semi-colon at the end of the last declaration in a
declaration block.
• Place the closing brace of a ruleset in the same column as
the first character of the ruleset.
• Separate each ruleset by a blank line.
Rule Formatting Example
.selector-1,
.selector-2,
.selector-3[type="text"] {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
display: block;
font-family: helvetica, arial, sans-serif;
color: #333;
background: #fff;
background: linear-gradient(#fff, rgba(0, 0, 0, 0.8));
}
Consistently Declare Property Order
• Makes it Easier to Read
• Makes it Easier for Teams to Share Code
Consistently Declare Property Order
.selector {
/* Positioning */
position: absolute;
z-index: 10;
top: 0;
right: 0;
bottom: 0;
left: 0;
 
/* Display & Box Model */
display: inline-block;
overflow: hidden;
box-sizing: border-box;
width: 100px;
height: 100px;
padding: 10px;
border: 10px solid #333;
margin: 10px;
 
/* Other */
background: #000;
color: #fff;
font-family: sans-serif;
font-size: 16px;
text-align: right;
}
Clock-Wise Rule
• Margin & Padding Work Clock-wise around the element
• margin: 5% 10% 15% 20%;
• margin-top : 5%;
• margin-right : 10%;
• margin-bottom : 15%;
• margin-left : 20%;
Element Layout Box
CSS Animations
• Do Not Use JavaScript Libraries for Animations
• CSS Animations are Native
• Run on the GPU
CSS Key-Frame Animations
• Allow You To Define Complex Animations
• Define Rules/Properties Along a Timeline
• Animate.css is a collection of turn-key animations
• http://daneden.me/animate
CSS Key-Frame Animations
• Can be Applied by adding and removing CSS classes on
an element
loginDlg.classList.add("fadeInDown");
showLogin.classList.add("fadeOut");
loginDlg.classList.remove("fadeOutUp");
CSS Key-Frame Animations
• Can be Applied by adding and removing CSS classes on
an element
loginDlg.classList.add("fadeInDown");
showLogin.classList.add("fadeOut");
loginDlg.classList.remove("fadeOutUp");
• http://bit.ly/1Lt1kTb
CSS Shapes
• CSS Can be Used to Create All Sorts of Shapes
• http://www.cssshapes.com/
Create a CSS Heart
• My Site’s Logo is a CSS Heart
• Here is how to create it:
• http://bit.ly/1NF3Sjf
Perfectly Align to Center
.my-class-parent {
position:relative;
}
.my-class {
position:absolute;
top:50%;
left:50%;
-webkit-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
}
High Performance Single Page Web
Applications
• Responsive Design
• Touch
• Mobile First
• SPA
• Extensible, Scalable Architecture
• Web Build and Workflow
• Goes Really Fast!
• ~395 Pages
• 20 Chapters
• $9.99

More Related Content

What's hot

What's hot (20)

Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS Tricks
 
CSS
CSSCSS
CSS
 
Css
CssCss
Css
 
HTML News Packages Lesson
HTML News Packages LessonHTML News Packages Lesson
HTML News Packages Lesson
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
 
CSS3 Introduction
CSS3 IntroductionCSS3 Introduction
CSS3 Introduction
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
How to dominate a free theme WCTO 2014
How to dominate a free theme WCTO 2014How to dominate a free theme WCTO 2014
How to dominate a free theme WCTO 2014
 
Unit 3 (it workshop).pptx
Unit 3 (it workshop).pptxUnit 3 (it workshop).pptx
Unit 3 (it workshop).pptx
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Maintainable CSS
Maintainable CSSMaintainable CSS
Maintainable CSS
 
Css.html
Css.htmlCss.html
Css.html
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)
 
Inline, Block and Positioning in CSS
Inline, Block and Positioning in CSSInline, Block and Positioning in CSS
Inline, Block and Positioning in CSS
 

Viewers also liked

Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworksNicole Ryan
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBrad Frost
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media QueriesRuss Weakley
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5Kenichi Kanai
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesLitmus
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 

Viewers also liked (10)

Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworks
 
AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web Design
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best Practices
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 

Similar to Css best practices style guide and tips

Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflowPeter Kaizer
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSZoe Gillenwater
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...SPTechCon
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSSSun Technlogies
 
Let's dig into the Omega Theme!
Let's dig into the Omega Theme!Let's dig into the Omega Theme!
Let's dig into the Omega Theme!Mediacurrent
 
W3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayW3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayadeveria
 
Responsive content
Responsive contentResponsive content
Responsive contenthonzie
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersMelvin John
 
The Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookThe Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookFuture Insights
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxTanu524249
 
Building Faster Websites
Building Faster WebsitesBuilding Faster Websites
Building Faster WebsitesCraig Walker
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewDiacode
 
HTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersHTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersJustin Lee
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pagesNilesh Bafna
 

Similar to Css best practices style guide and tips (20)

Web design-workflow
Web design-workflowWeb design-workflow
Web design-workflow
 
Web
WebWeb
Web
 
performance.ppt
performance.pptperformance.ppt
performance.ppt
 
web dev
web devweb dev
web dev
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill ...
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Let's dig into the Omega Theme!
Let's dig into the Omega Theme!Let's dig into the Omega Theme!
Let's dig into the Omega Theme!
 
W3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayW3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use today
 
Responsive content
Responsive contentResponsive content
Responsive content
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style Sheets
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for Developers
 
The Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookThe Future is Modular, Jonathan Snook
The Future is Modular, Jonathan Snook
 
Unit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptxUnit-3-CSS-BWT.pptx
Unit-3-CSS-BWT.pptx
 
Building Faster Websites
Building Faster WebsitesBuilding Faster Websites
Building Faster Websites
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
HTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersHTML5 for ASP.NET Developers
HTML5 for ASP.NET Developers
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 

More from Chris Love

Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API IntroductionChris Love
 
Introduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsIntroduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsChris Love
 
Introduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsIntroduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsChris Love
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website AssetsChris Love
 
Progressive Web Apps for Education
Progressive Web Apps for EducationProgressive Web Apps for Education
Progressive Web Apps for EducationChris Love
 
The server is dead going serverless to create a highly scalable application y...
The server is dead going serverless to create a highly scalable application y...The server is dead going serverless to create a highly scalable application y...
The server is dead going serverless to create a highly scalable application y...Chris Love
 
A Day Building Fast, Responsive, Extensible Single Page Applications
A Day Building Fast, Responsive, Extensible Single Page ApplicationsA Day Building Fast, Responsive, Extensible Single Page Applications
A Day Building Fast, Responsive, Extensible Single Page ApplicationsChris Love
 
Real World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker CachingReal World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker CachingChris Love
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applicationsDisrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applicationsChris Love
 
Service workers your applications never felt so good
Service workers   your applications never felt so goodService workers   your applications never felt so good
Service workers your applications never felt so goodChris Love
 
Develop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will loveDevelop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will loveChris Love
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizationsChris Love
 
Advanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms toolsAdvanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms toolsChris Love
 
Html5 Fit: Get Rid of Love Handles
Html5 Fit:  Get Rid of Love HandlesHtml5 Fit:  Get Rid of Love Handles
Html5 Fit: Get Rid of Love HandlesChris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere - Updated
Using Responsive Web Design To Make Your Web Work Everywhere - UpdatedUsing Responsive Web Design To Make Your Web Work Everywhere - Updated
Using Responsive Web Design To Make Your Web Work Everywhere - UpdatedChris Love
 
Implementing a Responsive Image Strategy
Implementing a Responsive Image StrategyImplementing a Responsive Image Strategy
Implementing a Responsive Image StrategyChris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereUsing Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereChris Love
 
10 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 201610 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 2016Chris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere Chris Love
 
An Introduction to Microsoft Edge
An Introduction to Microsoft EdgeAn Introduction to Microsoft Edge
An Introduction to Microsoft EdgeChris Love
 

More from Chris Love (20)

Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
 
Introduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsIntroduction to Progressive Web Applications
Introduction to Progressive Web Applications
 
Introduction to Progressive Web Applications
Introduction to Progressive Web ApplicationsIntroduction to Progressive Web Applications
Introduction to Progressive Web Applications
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website Assets
 
Progressive Web Apps for Education
Progressive Web Apps for EducationProgressive Web Apps for Education
Progressive Web Apps for Education
 
The server is dead going serverless to create a highly scalable application y...
The server is dead going serverless to create a highly scalable application y...The server is dead going serverless to create a highly scalable application y...
The server is dead going serverless to create a highly scalable application y...
 
A Day Building Fast, Responsive, Extensible Single Page Applications
A Day Building Fast, Responsive, Extensible Single Page ApplicationsA Day Building Fast, Responsive, Extensible Single Page Applications
A Day Building Fast, Responsive, Extensible Single Page Applications
 
Real World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker CachingReal World Lessons in Progressive Web Application & Service Worker Caching
Real World Lessons in Progressive Web Application & Service Worker Caching
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applicationsDisrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
 
Service workers your applications never felt so good
Service workers   your applications never felt so goodService workers   your applications never felt so good
Service workers your applications never felt so good
 
Develop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will loveDevelop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will love
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Advanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms toolsAdvanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms tools
 
Html5 Fit: Get Rid of Love Handles
Html5 Fit:  Get Rid of Love HandlesHtml5 Fit:  Get Rid of Love Handles
Html5 Fit: Get Rid of Love Handles
 
Using Responsive Web Design To Make Your Web Work Everywhere - Updated
Using Responsive Web Design To Make Your Web Work Everywhere - UpdatedUsing Responsive Web Design To Make Your Web Work Everywhere - Updated
Using Responsive Web Design To Make Your Web Work Everywhere - Updated
 
Implementing a Responsive Image Strategy
Implementing a Responsive Image StrategyImplementing a Responsive Image Strategy
Implementing a Responsive Image Strategy
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work EverywhereUsing Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere
 
10 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 201610 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 2016
 
Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere Using Responsive Web Design To Make Your Web Work Everywhere
Using Responsive Web Design To Make Your Web Work Everywhere
 
An Introduction to Microsoft Edge
An Introduction to Microsoft EdgeAn Introduction to Microsoft Edge
An Introduction to Microsoft Edge
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Css best practices style guide and tips

  • 1. CSS Best Practices, Style Guide, and Tips #ITDEVCON Chris Love http://love2dev.com @ChrisLove
  • 2. Who Am I? • ASP.NET MVP • ASP Insider • MS Edge User Agent • Author • Speaker • Tweaker, Lover of Web, JavaScript, CSS & HTML5 • @ChrisLove • Love2Dev.com #ITDEVCON
  • 3. High Performance Single Page Web Applications • Responsive Design • Touch • Mobile First • SPA • Extensible, Scalable Architecture • Web Build and Workflow • Goes Really Fast! • ~395 Pages • 20 Chapters • $9.99 #ITDEVCON
  • 4. Slide Decks & Source Code • Slide Deck – http://slidesha.re/19NZInK • Source Code – http://GitHub.com/docluv #ITDEVCON
  • 5. CSS • Language Defining Rendering Rules #ITDEVCON
  • 6. CSS .main-content { overflow: hidden; left: 6.3166666%; right: 0; top: 50px; bottom: 4.166666%; position: absolute; border-radius: 5px 5px 0 0; background-color: #000000; -moz-transition: all 700ms ease-out; -o-transition: all 700ms ease-out; -webkit-transition: all 700ms ease-out; transition: all 700ms ease-out; } #ITDEVCON Selector/Rule Properties Vendor Specific
  • 7. CSS •Rules • Defined using selector syntax •Properties • The specifics •Media Queries • Define Rules Based on Browser & Device Characteristics #ITDEVCON
  • 8. CSS Property Units •px – pixels •% - percent •em – relative to the element’s font-size •rem – Relative to the root element’s font-size •vh/vw – Viewport Height/Viewport Width •Any 0 does not require a unit #ITDEVCON
  • 9. CSS Selector Syntax • Element • H1, DIV, P • Class • .btn, . spa-child-view • ID • #tryToAvoid #ITDEVCON
  • 10. Advanced CSS Selector Syntax • Nested Selectors • Allows You To Apply Rules to Children of Matched Elements • .main-content p • Be careful to avoid complexity • Dynamic By Attributes • script[class='spa-view'] #ITDEVCON
  • 15. Customize Social Links a[href*="twitter.com"] { color:#55acee; } a[href*="facebook.com"] { color:#3b5998; } a[href*="google.com"] { color:#db4437; } #ITDEVCON
  • 16. Remove webkit Input Border input[type="text"]:focus { outline: none; } #ITDEVCON
  • 17. psuedo-classes • Define CSS Rules for Element States • Hover • Active • Define Rules for hidden elements • :before, :after • Define Rules for nth Element • :nth-of-type(3n)
  • 18. Content Property • Defines ‘text’ value for matched element • Useful with :before and :after pseudo element
  • 19. Responsive Table Trick • Tables Create a Unique Responsive Design Problem • Change CSS To Change Rendering Rules • Turn Table into a fake set of DIVs • Leverage content property to define value labels • https://css-tricks.com/responsive-data-tables/
  • 21. Responsive Table Trick <table> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Job Title</th> </tr> </thead> <tbody> <tr> <td>James</td> <td>Matman</td> <td>Chief Sandwich Eater</td> </tr> <tr> <td>The</td> <td>Tick</td> <td>Crimefighter Sorta</td> </tr> </tbody> </table>
  • 22. Responsive Table Trick @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) { table, thead, tbody, th, td, tr { display: block; } } #ITDEVCON
  • 23. Responsive Table Trick td:nth-of-type(1):before { content: "First Name"; } td:nth-of-type(2):before { content: "Last Name"; } td:nth-of-type(3):before { content: "Job Title"; } td:nth-of-type(4):before { content: "Favorite Color"; } td:nth-of-type(5):before { content: "Wars of Trek?"; } td:nth-of-type(6):before { content: "Porn Name"; } td:nth-of-type(7):before { content: "Date of Birth"; } td:nth-of-type(8):before { content: "Dream Vacation City"; } td:nth-of-type(9):before { content: "GPA"; } td:nth-of-type(10):before { content: "Arbitrary Data"; }
  • 24. CSS Selector Specificity • Complex Specificity • .main-content > article #myArticleId p • Leads to large CSS files • Makes Code Unmanageable • Lower the Score the Better • Browsers Parse Selectors Right to Left • * Avoid Universal Selector
  • 25. Right-Left Rule • .main-content > article #myArticleId p • Translates to: • #myArticleId p • Think More Like the Browser When Defining Selectors
  • 26. Calculate CSS Specificity • Count the Inline Style • count the number of ID selectors in the selector (= a) • count the number of class selectors, attributes selectors, and pseudo- classes in the selector (= b) • count the number of type selectors and pseudo-elements in the selector (= c) • ignore the universal selector
  • 28. BEM Naming Convention • Block • Element • Modifier • Bootstrap and Primer Good Examples
  • 29. BEM Naming Convention • .btn {…} • .btn-primary {…} • .btn-primary:disabled {…} • .btn-xs {…} • Might also see __ between words
  • 30. BEM Naming Convention • <button type="button" class="btn btn-primary">Primary</button> • <button type="button" class="btn btn-success">Success</button> • <button type="button" class="btn btn-info">Info</button> • <button type="button" class="btn btn-warning">Warning</button>
  • 31. CSS Cascading • Last, Most Specific Rule Wins • Be mindful of your CSS Definition Order • Overwrites Previously Defined Rules • Simple rule make this easy to maintain and create
  • 32. Responsive Design “this unspoken agreement to pretend that we had a certain size. And that size changed over the years. For a while, we all sort of tacitly agreed that 640 by 480 was the right size, and then later than changed to 800:600, and 1024; we seem to have settled on this 960 pixel as being this like, default. It’s still unknown. We still don’t know the size of the browser; it’s just like this consensual hallucination that we’ve all agreed to participate in: “Let’s assume the browser has a browser width of at least 960 pixels.” Jeremy Keith bit.ly/1bhH6rw
  • 34. Responsive Web Design • Introduced by Ethan Marcotte 2010 - bit.ly/178an9e • Web Design Approach To Create An Optimal Viewing Experience Across All Browser ViewPorts • Fluid Layouts • Media Queries • Minimal if any JavaScript Required
  • 35. Fluid Layout • Stretch as the Browser ViewPort Changes • Browser’s Viewable Area Inside the Chrome • Serve as the Foundation for the Web Application Layout • Great Way To Create Native Like Experience
  • 36. Fluid Layout • Leverage Absolute Positioning • Enables Fixed Positioning Without position:fixed • Leverage overflow scrolling
  • 37. Media Queries @media (min-width: 600px) { /* Selectors & Rules */ } @media (min-width: 820px) { /* Selectors & Rules */ } @media (min-width: 1080px) { /* Selectors & Rules */ }
  • 38. Avoid Embedded Styles • Don't separate content from design • Cause more maintenance headaches • Make your pages larger • Do not take advantage of Http Caching • Lead to Duplicate Rules
  • 39. CSS - Files • Should • Use External Files • Hosted on a CDN • Bundled & Minified * • HTTP/2 Changes the Bundling Rule
  • 40. CSS – Debug Files • Should • Use Many Files • They Should Correlate to a Purpose • View • Component • Layout
  • 42. CSS Best Practices • Link to External Files in the HEAD • Ensures CSS read before HTML • Avoid Using @import • Causes CSS to be Parsed After Document
  • 43. CSS Reset • Establishes a Common Base • Each Browser has a default CSS stylesheet • Many Resets Availble • Normalize.css probably most popular • Popular libraries have resets; ex bootstrap uses normalize
  • 44. CSS Libraries • Many Available • Bootstrap is the current defacto standard • Primer based on Boostrap • Created by bootstrap author • GitHub’s internal library • https://github.com/primer/primer
  • 45. CSS Libraries • Be Careful to not be Completely Dependent on Library • Understand How CSS Rules, Apply Best Practices • Build Your Own Custom Version • Grunt/Gulp
  • 46. Critical CSS • The CSS Required to Render The Above the Fold Content • Embed Inline, in HEAD element • Instant Render if HTML < 14kb • Works great for a SPA • criticalCSS Node Module • https://www.npmjs.com/package/criticalcss
  • 47. Critical CSS Grunt grunt.initConfig({ criticalcss: { custom: { options: { url: "http://localhost:4000", width: 1200, height: 900, outputfile: "dist/critical.css", filename: "/path/to/local/all.css", // Using path.resolve( path.join( ... ) ) is a good idea here buffer: 800*1024, ignoreConsole: false } } }, });
  • 48. UnCSS Grunt uncss: { dist: { src: ['app/index.html'], dest: 'app/css/tidy.css', options: { report: 'min' } } } https://www.npmjs.com/package/grunt-uncss
  • 49. CSS Code Style • Define Section Titles /*------------------------------------* $MAIN *------------------------------------*/
  • 50. CSS Rule Formatting • Use one discrete selector per line in multi-selector rulesets. • Include a single space before the opening brace of a ruleset. • Include one declaration per line in a declaration block. • Use one level of indentation for each declaration. • Include a single space after the colon of a declaration.
  • 51. CSS Rule Formatting • Use lowercase and shorthand hex values, e.g., `#aaa`. • Use single or double quotes consistently. Preference is for double quotes, e.g., `content: ""`. • Quote attribute values in selectors, e.g., `input[type="checkbox"]`. • _Where allowed_, avoid specifying units for zero-values, e.g., `margin: 0`.
  • 52. CSS Rule Formatting • Include a space after each comma in comma-separated property or function values. • Include a semi-colon at the end of the last declaration in a declaration block. • Place the closing brace of a ruleset in the same column as the first character of the ruleset. • Separate each ruleset by a blank line.
  • 53. Rule Formatting Example .selector-1, .selector-2, .selector-3[type="text"] { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: block; font-family: helvetica, arial, sans-serif; color: #333; background: #fff; background: linear-gradient(#fff, rgba(0, 0, 0, 0.8)); }
  • 54. Consistently Declare Property Order • Makes it Easier to Read • Makes it Easier for Teams to Share Code
  • 55. Consistently Declare Property Order .selector { /* Positioning */ position: absolute; z-index: 10; top: 0; right: 0; bottom: 0; left: 0;   /* Display & Box Model */ display: inline-block; overflow: hidden; box-sizing: border-box; width: 100px; height: 100px; padding: 10px; border: 10px solid #333; margin: 10px;   /* Other */ background: #000; color: #fff; font-family: sans-serif; font-size: 16px; text-align: right; }
  • 56. Clock-Wise Rule • Margin & Padding Work Clock-wise around the element • margin: 5% 10% 15% 20%; • margin-top : 5%; • margin-right : 10%; • margin-bottom : 15%; • margin-left : 20%;
  • 58. CSS Animations • Do Not Use JavaScript Libraries for Animations • CSS Animations are Native • Run on the GPU
  • 59. CSS Key-Frame Animations • Allow You To Define Complex Animations • Define Rules/Properties Along a Timeline • Animate.css is a collection of turn-key animations • http://daneden.me/animate
  • 60. CSS Key-Frame Animations • Can be Applied by adding and removing CSS classes on an element loginDlg.classList.add("fadeInDown"); showLogin.classList.add("fadeOut"); loginDlg.classList.remove("fadeOutUp");
  • 61. CSS Key-Frame Animations • Can be Applied by adding and removing CSS classes on an element loginDlg.classList.add("fadeInDown"); showLogin.classList.add("fadeOut"); loginDlg.classList.remove("fadeOutUp"); • http://bit.ly/1Lt1kTb
  • 62. CSS Shapes • CSS Can be Used to Create All Sorts of Shapes • http://www.cssshapes.com/
  • 63. Create a CSS Heart • My Site’s Logo is a CSS Heart • Here is how to create it: • http://bit.ly/1NF3Sjf
  • 64. Perfectly Align to Center .my-class-parent { position:relative; } .my-class { position:absolute; top:50%; left:50%; -webkit-transform:translate(-50%, -50%); transform:translate(-50%, -50%); }
  • 65. High Performance Single Page Web Applications • Responsive Design • Touch • Mobile First • SPA • Extensible, Scalable Architecture • Web Build and Workflow • Goes Really Fast! • ~395 Pages • 20 Chapters • $9.99