SlideShare a Scribd company logo
© 2018 ClickStart – www.clickstart.net
CSS Best Practices
Scott DeLoach – scott@clickstart.net ClickStart – www.clickstart.net
During this presentation, I will discuss advanced CSS techniques with an emphasis on what’s new in
CSS3.
Ten CSS best practices
▪ Do not use inline formatting
▪ Organize definitions and use a naming convention
▪ Add comments
▪ Use a reset/normalize stylesheet - meyerweb.com/eric/tools/css/reset or
necolas.github.io/normalize.css
▪ Use an auto-prefixer to support old browsers and new features
▪ Use DRY ("Don't Repeat Yourself") techniques
▪ Make selectors as specific as possible
▪ Remove unused CSS rules
▪ Test in multiple browsers on multiple devices
▪ Keep learning
What’s new in CSS
▪ ::grammar-error pseudo element
▪ ::spelling-error pseudo element
▪ :fullscreen (aka full-screen) pseudo class
▪ :target pseudo class and scroll-snap property
▪ calc() function
▪ @supports rule
▪ variables
Browser compatibility
Auto prefixing
leaverou.github.io/prefixfree
github.com/ai/autoprefixer
Detect HTML, CSS, and JavaScript features
www.modernizr.com
Research CSS support in browsers
www.caniuse.com
IE compatibility
www.selectivizr.com
github.com/postcss/postcss
© 2018 ClickStart – www.clickstart.net
DRY coding
“Don’t repeat yourself.”
Grouping selectors
h1, h2, h3, h4, h5, h6 { color: green; }
rems measurement unit
ul { font-size: .9rem; }
Code samples — Prism
www.prismjs.com
Google Material Design
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<i class="material-icons">face</i>
See www.google.com/design/spec/material-design/introduction.html
Font Awesome
<link href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet"
crossorigin="anonymous" />
<i class="fas fa-print fa-3x"></i>
Variables
Variables
:root { --main-bg-color: orange; }
.exBox {
background-color: var(--main-bg-color);
color: white;
}
.exText {
background-color: var(--main-bg-color);
color: white;
}
See also
SASS - http://sass-lang.com
LESS - http://lesscss.org
currentColor variable
p.example a {
text-decoration: none;
color: currentcolor;
border-bottom: 1px dashed currentcolor;
}
© 2018 ClickStart – www.clickstart.net
calc() function
:root { --fontSize: 1rem; }
h6 { font-size: calc(var(--fontSize) * 2); }
Responsive design
display:grid
.wrapper { display: grid; grid-gap: 20px; grid-template-columns: repeat(auto-fit,
9rem); grid-template-rows: repeat(2, 12rem); }
.wrapper div { background-color: green; color: white; border-radius: 6px; font-size:
10rem; text-align: center; }
<div class="wrapper">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
system-ui font
body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; }
Link target formatting
*:target { background-color: yellow; }
Responsive images
img {
min-height : auto; min-width : 480px; /* max width of mobile medium */
max-height : auto;
max-width : 100%;
}
Responsive tables
/* 47.9375em mobile landscape max width */
@media (max-width: 47.9375em) {
table { display: block; width: 100%; }
table caption { display: block; }
table thead { display: none; visibility: hidden; }
table tbody, table tr, table th, table td { border: 0; display: block; text-align:
left; }
table th[data-title]:before, table td[data-title]:before { content: attr(data-
title) ": "; font-weight: bold; }
table td:empty { display: none; }
}
What's next
▪ Breaks - spread, column, region
▪ Case insensitivity — p[class$="example" i] { }
© 2018 ClickStart – www.clickstart.net
▪ Colors — gray(), color(), HWB
▪ Float — inline-start, inline-end, defer, reference, offset
▪ Ligatures and kerning
▪ Media queries — display size, color depth, aspect ratio
▪ Overflow — fade, fragment formatting
▪ Nesting
▪ Pseudo classes — :blank, :empty, and :has
▪ revert keyword
▪ Selectors — custom and parent
www.w3.org/Style/CSS/current-work
Tracking CSS developments
▪ w3.org/style/css/current-work
▪ ishoudinireadyyet.com
Where to find CSS examples
▪ codepad.co
▪ codepen.com
▪ css-tricks.com
▪ cssdeck.com
▪ lea.verou.me
▪ littlesnippets.net
About the presenter
Scott DeLoach is the Founder of ClickStart, where he provides training and
consulting for MadCap Flare, embedded user assistance, JavaScript/jQuery,
CSS, and HTML5. He has been developing browser-based help systems for 20
years, and he has received four Best in Show awards for his work from STC.
Scott is a certified Flare and Doc-to-Help instructor, and he is the author of
MadCap Flare: The Definitive Guide, CSS to the Point, and HTML5 to the Point. For more
information about Scott's books, training, or consulting, see www.clickstart.net.

More Related Content

What's hot (7)

PPTX
PhDigital Bootcamp: Web Development Concepts
Cindy Royal
 
PDF
Malte Wessel - SASS Preprocessor / Compass / YDN Brand
drbreak
 
PPTX
CSS3 Implementable Features
Estelle Weyl
 
PDF
Lesson 02
Gene Babon
 
PDF
CSS Nite in Ginza, Vol.55 (Shift 4)
swwwitch inc.
 
PDF
IE9에서 HTML5 개발하기
Reagan Hwang
 
PDF
"Вклад Adobe в Web". Дмитрий Барановский, Adobe
Yandex
 
PhDigital Bootcamp: Web Development Concepts
Cindy Royal
 
Malte Wessel - SASS Preprocessor / Compass / YDN Brand
drbreak
 
CSS3 Implementable Features
Estelle Weyl
 
Lesson 02
Gene Babon
 
CSS Nite in Ginza, Vol.55 (Shift 4)
swwwitch inc.
 
IE9에서 HTML5 개발하기
Reagan Hwang
 
"Вклад Adobe в Web". Дмитрий Барановский, Adobe
Yandex
 

Similar to CSS Best Practices - tcworld 2018, Scott DeLoach, ClickStart (20)

PPTX
Introduction to HTML+CSS+Javascript.pptx
deepuranjankumar2002
 
PDF
Pfnp slides
William Myers
 
PDF
Intro to CSS in MadCap Flare - MadWorld 2016, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Nanoformats
rozario
 
PDF
Introduction to HTML-CSS-Javascript.pdf
DakshPratapSingh1
 
PDF
Accelerated Stylesheets
Wynn Netherland
 
PPTX
Introduction to HTML+CSS+Javascript.pptx
AliRaza899305
 
PPTX
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT
 
PPTX
Css methods architecture
Lasha Sumbadze
 
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
PDF
Css3 and gwt in perfect harmony
jdramaix
 
PDF
Css3 and gwt in perfect harmony
Arcbees
 
PDF
GDI Seattle Intermediate HTML and CSS Class 1
Heather Rock
 
PPTX
wd project.pptx
dsffsdf1
 
PPTX
Cascading Style Sheet
KushagraChadha1
 
PPTX
Introduction to HTML+CSS+Javascript by Deepu.pptx
deepuranjankumar08
 
PDF
Html 5 mobile - nitty gritty
Mario Noble
 
PDF
Doing more with LESS
jsmith92
 
PDF
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
Introduction to HTML+CSS+Javascript.pptx
deepuranjankumar2002
 
Pfnp slides
William Myers
 
Intro to CSS in MadCap Flare - MadWorld 2016, Scott DeLoach, ClickStart
Scott DeLoach
 
Nanoformats
rozario
 
Introduction to HTML-CSS-Javascript.pdf
DakshPratapSingh1
 
Accelerated Stylesheets
Wynn Netherland
 
Introduction to HTML+CSS+Javascript.pptx
AliRaza899305
 
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT
 
Css methods architecture
Lasha Sumbadze
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
Css3 and gwt in perfect harmony
jdramaix
 
Css3 and gwt in perfect harmony
Arcbees
 
GDI Seattle Intermediate HTML and CSS Class 1
Heather Rock
 
wd project.pptx
dsffsdf1
 
Cascading Style Sheet
KushagraChadha1
 
Introduction to HTML+CSS+Javascript by Deepu.pptx
deepuranjankumar08
 
Html 5 mobile - nitty gritty
Mario Noble
 
Doing more with LESS
jsmith92
 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
Ad

More from Scott DeLoach (20)

PDF
Formatting Images with CSS in MadCap Flare - MadCap webinar, Scott DeLoach, C...
Scott DeLoach
 
PDF
Dynamic User Assistance in MadCap Flare - MadWorld 2019, Scott DeLoach, Click...
Scott DeLoach
 
PDF
Enhancing MadCap Flare HTML5 Responsive Layout and Design - MadWorld 2019, Sc...
Scott DeLoach
 
PDF
Microcontent Authoring - Nordic Techkomm 2019, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Advanced Skinless HTML5 Design with MadCap Flare - MadWorld 2018, Scott DeLoa...
Scott DeLoach
 
PDF
Extreme CSS Techniques - MadWorld Europe 2018, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Adapting Content for Mobile Devices - tcworld 2017, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Best-in-Class Embedded User Assistance - UA Europe 2017, Scott DeLoach, Click...
Scott DeLoach
 
PDF
Cutting Edge HTML5 Design with MadCap Flare - tcworld 2017, Scott DeLoach, Cl...
Scott DeLoach
 
PDF
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Scott DeLoach
 
PDF
Responsive Content: A CSS-based Approach - MadWorld 2015, Scott DeLoach, Clic...
Scott DeLoach
 
PDF
Best Practices for Going Mobile - MadWorld 2015, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Applying Responsive Web Design (RWD) to UA - WritersUA East 2015, Scott DeLoa...
Scott DeLoach
 
PDF
Core Web Standards and Competencies - WritersUA East 2015, Scott DeLoach, Cli...
Scott DeLoach
 
PDF
MadCap Flare: Advanced Table Styles - MadWorld 2014, Scott DeLoach, ClickStart
Scott DeLoach
 
PDF
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Scott DeLoach
 
PDF
How to Not Let Team Authoring Drive You Crazy - MadWorld 2013, Scott DeLoach,...
Scott DeLoach
 
PDF
Using MadCap Flare Reports and MadCap Analyzer - MadWorld 2013, Scott DeLoach...
Scott DeLoach
 
DOC
Embedded UA 101 - STC Summit 2013, Scott DeLoach, ClickStart
Scott DeLoach
 
Formatting Images with CSS in MadCap Flare - MadCap webinar, Scott DeLoach, C...
Scott DeLoach
 
Dynamic User Assistance in MadCap Flare - MadWorld 2019, Scott DeLoach, Click...
Scott DeLoach
 
Enhancing MadCap Flare HTML5 Responsive Layout and Design - MadWorld 2019, Sc...
Scott DeLoach
 
Microcontent Authoring - Nordic Techkomm 2019, Scott DeLoach, ClickStart
Scott DeLoach
 
Advanced Skinless HTML5 Design with MadCap Flare - MadWorld 2018, Scott DeLoa...
Scott DeLoach
 
Extreme CSS Techniques - MadWorld Europe 2018, Scott DeLoach, ClickStart
Scott DeLoach
 
Adapting Content for Mobile Devices - tcworld 2017, Scott DeLoach, ClickStart
Scott DeLoach
 
Best-in-Class Embedded User Assistance - UA Europe 2017, Scott DeLoach, Click...
Scott DeLoach
 
Cutting Edge HTML5 Design with MadCap Flare - tcworld 2017, Scott DeLoach, Cl...
Scott DeLoach
 
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Scott DeLoach
 
Responsive Content: A CSS-based Approach - MadWorld 2015, Scott DeLoach, Clic...
Scott DeLoach
 
Best Practices for Going Mobile - MadWorld 2015, Scott DeLoach, ClickStart
Scott DeLoach
 
Best Practices for Embedded UA - WritersUA 2012, Scott DeLoach, ClickStart
Scott DeLoach
 
Applying Responsive Web Design (RWD) to UA - WritersUA East 2015, Scott DeLoa...
Scott DeLoach
 
Core Web Standards and Competencies - WritersUA East 2015, Scott DeLoach, Cli...
Scott DeLoach
 
MadCap Flare: Advanced Table Styles - MadWorld 2014, Scott DeLoach, ClickStart
Scott DeLoach
 
Developing Context-sensitive Help for Web-based Applications - Scott DeLoach,...
Scott DeLoach
 
How to Not Let Team Authoring Drive You Crazy - MadWorld 2013, Scott DeLoach,...
Scott DeLoach
 
Using MadCap Flare Reports and MadCap Analyzer - MadWorld 2013, Scott DeLoach...
Scott DeLoach
 
Embedded UA 101 - STC Summit 2013, Scott DeLoach, ClickStart
Scott DeLoach
 
Ad

Recently uploaded (20)

PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PPTX
internet básico presentacion es una red global
70965857
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
PPTX
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
internet básico presentacion es una red global
70965857
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
Orchestrating things in Angular application
Peter Abraham
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 

CSS Best Practices - tcworld 2018, Scott DeLoach, ClickStart

  • 1. © 2018 ClickStart – www.clickstart.net CSS Best Practices Scott DeLoach – [email protected] ClickStart – www.clickstart.net During this presentation, I will discuss advanced CSS techniques with an emphasis on what’s new in CSS3. Ten CSS best practices ▪ Do not use inline formatting ▪ Organize definitions and use a naming convention ▪ Add comments ▪ Use a reset/normalize stylesheet - meyerweb.com/eric/tools/css/reset or necolas.github.io/normalize.css ▪ Use an auto-prefixer to support old browsers and new features ▪ Use DRY ("Don't Repeat Yourself") techniques ▪ Make selectors as specific as possible ▪ Remove unused CSS rules ▪ Test in multiple browsers on multiple devices ▪ Keep learning What’s new in CSS ▪ ::grammar-error pseudo element ▪ ::spelling-error pseudo element ▪ :fullscreen (aka full-screen) pseudo class ▪ :target pseudo class and scroll-snap property ▪ calc() function ▪ @supports rule ▪ variables Browser compatibility Auto prefixing leaverou.github.io/prefixfree github.com/ai/autoprefixer Detect HTML, CSS, and JavaScript features www.modernizr.com Research CSS support in browsers www.caniuse.com IE compatibility www.selectivizr.com github.com/postcss/postcss
  • 2. © 2018 ClickStart – www.clickstart.net DRY coding “Don’t repeat yourself.” Grouping selectors h1, h2, h3, h4, h5, h6 { color: green; } rems measurement unit ul { font-size: .9rem; } Code samples — Prism www.prismjs.com Google Material Design <link href="https://fonts.googleapis.com/icon?family=Material+Icons" /> <i class="material-icons">face</i> See www.google.com/design/spec/material-design/introduction.html Font Awesome <link href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet" crossorigin="anonymous" /> <i class="fas fa-print fa-3x"></i> Variables Variables :root { --main-bg-color: orange; } .exBox { background-color: var(--main-bg-color); color: white; } .exText { background-color: var(--main-bg-color); color: white; } See also SASS - http://sass-lang.com LESS - http://lesscss.org currentColor variable p.example a { text-decoration: none; color: currentcolor; border-bottom: 1px dashed currentcolor; }
  • 3. © 2018 ClickStart – www.clickstart.net calc() function :root { --fontSize: 1rem; } h6 { font-size: calc(var(--fontSize) * 2); } Responsive design display:grid .wrapper { display: grid; grid-gap: 20px; grid-template-columns: repeat(auto-fit, 9rem); grid-template-rows: repeat(2, 12rem); } .wrapper div { background-color: green; color: white; border-radius: 6px; font-size: 10rem; text-align: center; } <div class="wrapper"> <div>1</div> <div>2</div> <div>3</div> </div> system-ui font body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } Link target formatting *:target { background-color: yellow; } Responsive images img { min-height : auto; min-width : 480px; /* max width of mobile medium */ max-height : auto; max-width : 100%; } Responsive tables /* 47.9375em mobile landscape max width */ @media (max-width: 47.9375em) { table { display: block; width: 100%; } table caption { display: block; } table thead { display: none; visibility: hidden; } table tbody, table tr, table th, table td { border: 0; display: block; text-align: left; } table th[data-title]:before, table td[data-title]:before { content: attr(data- title) ": "; font-weight: bold; } table td:empty { display: none; } } What's next ▪ Breaks - spread, column, region ▪ Case insensitivity — p[class$="example" i] { }
  • 4. © 2018 ClickStart – www.clickstart.net ▪ Colors — gray(), color(), HWB ▪ Float — inline-start, inline-end, defer, reference, offset ▪ Ligatures and kerning ▪ Media queries — display size, color depth, aspect ratio ▪ Overflow — fade, fragment formatting ▪ Nesting ▪ Pseudo classes — :blank, :empty, and :has ▪ revert keyword ▪ Selectors — custom and parent www.w3.org/Style/CSS/current-work Tracking CSS developments ▪ w3.org/style/css/current-work ▪ ishoudinireadyyet.com Where to find CSS examples ▪ codepad.co ▪ codepen.com ▪ css-tricks.com ▪ cssdeck.com ▪ lea.verou.me ▪ littlesnippets.net About the presenter Scott DeLoach is the Founder of ClickStart, where he provides training and consulting for MadCap Flare, embedded user assistance, JavaScript/jQuery, CSS, and HTML5. He has been developing browser-based help systems for 20 years, and he has received four Best in Show awards for his work from STC. Scott is a certified Flare and Doc-to-Help instructor, and he is the author of MadCap Flare: The Definitive Guide, CSS to the Point, and HTML5 to the Point. For more information about Scott's books, training, or consulting, see www.clickstart.net.