SlideShare a Scribd company logo
TACTICAL
HTML & CSS
Shay Howe
@shayhowe
learn.shayhowe.com
MODULAR
HTML & CSS
WORKSHOP
@shayhoweModular HTML & CSS
Shay Howe
@shayhowe
learn.shayhowe.com
@shayhoweModular HTML & CSS
1. The Problem
2. Groundwork
3. Assembling Layout
4. Accommodating Content
5. Onward
OUR SCHEDULE
@shayhoweModular HTML & CSS
THE
PROBLEM
The Gust by Willem van de Velde the Younger
@shayhoweModular HTML & CSS
COMMON PROBLEMS
• Websites have difficulty scaling
• Code becomes brittle
• Files and code bases begin to swell
@shayhoweModular HTML & CSS
WHAT’S WRONG
• Best practices aren’t exactly best practices
• Standards need to evolve
@shayhoweModular HTML & CSS
BEST BAD PRACTICES
• Avoid extra elements
• Avoid classes
• Leverage type selectors
• Leverage descendent selectors
@shayhoweModular HTML & CSS
BEST BAD PRACTICES
Avoiding classes
section	
  ul#nav	
  li	
  {...}
section:nth-­‐child(2)	
  div:nth-­‐child(7)	
  >	
  a	
  {...}
Leveraging selectors
a.btn	
  {...}
#main	
  a.btn	
  {...}
#main	
  div.feature	
  a.btn	
  {...}
@shayhoweModular HTML & CSS
BEST BAD PRACTICES
Bad
#contact	
  li:nth-­‐child(1)	
  input,
#contact	
  li:nth-­‐child(2)	
  input	
  {
	
  	
  width:	
  160px;
}
#contact	
  li:nth-­‐child(3)	
  textarea	
  {
	
  	
  width:	
  280px;
}
@shayhoweModular HTML & CSS
BEST BAD PRACTICES
Good
.col-­‐1	
  {
	
  	
  width:	
  160px;
}
.col-­‐2	
  {
	
  	
  width:	
  280px;
}
@shayhoweModular HTML & CSS
SPECIFICITY?
• Specificity determines which styles are applied
• Each selector has a specificity weight
• High specificity beats low specificity
• Low specificity is key
@shayhoweModular HTML & CSS
MEASURING SPECIFICITY
Formula
• IDs, Classes/Pseudo-classes/Attributes, Elements
High Specificity (Bad)
#primary	
  #main	
  div.gallery	
  figure.media
IDs: 2, Classes: 2, Elements: 2 — Compiled: 2–2–2
Low Specificity (Good)
.gallery-­‐media
IDs: 0, Classes: 1, Elements: 0 — Compiled: 0–1–0
@shayhoweModular HTML & CSS
@shayhoweModular HTML & CSS
WATCH SPECIFICITY
• Be explicit
• Keep specificity low
• Never use IDs or !important
• Avoid nested selectors (#main	
  .spotlight	
  strong	
  span)
@shayhoweModular HTML & CSS
WATCH SPECIFICITY
Bad
#primary	
  #main	
  div.gallery	
  {
	
  	
  text-­‐transform:	
  uppercase;
}
#primary	
  #main	
  div.gallery	
  figure.media	
  {
	
  	
  background:	
  #ccc;
}
@shayhoweModular HTML & CSS
WATCH SPECIFICITY
Good
.gallery	
  {
	
  	
  text-­‐transform:	
  uppercase;
}
.gallery-­‐media	
  {
	
  	
  background:	
  #ccc;
}
Parade of the Black Sea Fleet by Ivan Aivazovsky
@shayhoweModular HTML & CSS
MAINTAINABILITY
Code must be...
• Organized
• Modular
• Performant
@shayhoweModular HTML & CSS
METHODOLOGIES
OOCSS
• Object-Oriented CSS
From Nicole Sullivan – oocss.org
SMACSS
• Scalable and Modular Architecture for CSS
From Jonathan Snook – smacss.com
@shayhoweModular HTML & CSS
GROUNDWORK
@shayhoweModular HTML & CSS
REUSE CODE
• Do not duplicate code
• Remove old code
• Defer loading subsequent styles
@shayhoweModular HTML & CSS
REUSE CODE
Bad
.news	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
}
.social	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
}
@shayhoweModular HTML & CSS
REUSE CODE
Good
.news,
.social	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
}
Better
.feat-­‐box	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
}
@shayhoweModular HTML & CSS
USE CLASSES
• Write understandable class names
• Avoid unnecessary nesting
• Use same strength specificity
@shayhoweModular HTML & CSS
USE CLASSES
Bad
.feat-­‐box	
  .callout	
  .pr	
  {
	
  	
  font-­‐size:	
  12px;
}
.feat-­‐box	
  .callout	
  .pr	
  .un	
  {
	
  	
  color:	
  #39f;
}
@shayhoweModular HTML & CSS
USE CLASSES
Good
.feat-­‐box	
  .price	
  {
	
  	
  font-­‐size:	
  12px;
}
.feat-­‐box	
  .unit	
  {
	
  	
  color:	
  #39f;
}
@shayhoweModular HTML & CSS
USE CLASSES
Bad
.btn.large	
  {
	
  	
  font-­‐size:	
  24px;	
  	
  
	
  	
  padding:	
  15px	
  30px;
}
<div	
  class="btn	
  large">...</div>
@shayhoweModular HTML & CSS
USE CLASSES
Good
.btn-­‐large	
  {
	
  	
  font-­‐size:	
  24px;
	
  	
  padding:	
  15px	
  30px;
}
<div	
  class="btn-­‐large">...</div>
@shayhoweModular HTML & CSS
ASSEMBLING
LAYOUT
@shayhoweModular HTML & CSS
ABSTRACT STRUCTURE
• Separate presentation (or theme) from layout
• Create an object layer for layout
• Create a skin layer for theme
• Use a grid
@shayhoweModular HTML & CSS
ABSTRACT STRUCTURE
Bad
.news	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  400px;
}
<div	
  class="news">...</div>
@shayhoweModular HTML & CSS
ABSTRACT STRUCTURE
Good
.grid-­‐4	
  {
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  400px;
}
.feat-­‐box	
  {
	
  	
  background:	
  #eee;
	
  	
  color:	
  #666;
}
<div	
  class="grid-­‐4	
  feat-­‐box">...</div>
@shayhoweModular HTML & CSS
TRANSPARENTIZE ELEMENTS
• Stylize elements to be transparent
• Keep visual properties apart from layout
properties
@shayhoweModular HTML & CSS
TRANSPARENTIZE ELEMENTS
Bad
.pagination	
  {
	
  	
  border-­‐radius:	
  5px;
	
  	
  border:	
  1px	
  solid	
  #eee;
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  620px;
}
<ul	
  class="pagination">...</ul>
@shayhoweModular HTML & CSS
TRANSPARENTIZE ELEMENTS
Good
.grid-­‐8	
  {
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  620px;
}
.offset-­‐box	
  {
	
  	
  border-­‐radius:	
  5px;
	
  	
  border:	
  1px	
  solid	
  #eee;
}
<ul	
  class="grid-­‐8	
  offset-­‐box">...</ul>
@shayhoweModular HTML & CSS
CREATE ADAPTABLE LAYOUTS
• Height and width should be flexible
• Height should extend with content
• Width should extend with a grid
@shayhoweModular HTML & CSS
CREATE ADAPTABLE LAYOUTS
Bad
#main	
  {
	
  	
  float:	
  left;
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  620px;
}
#aside	
  {
	
  	
  float:	
  left;
	
  	
  margin:	
  0	
  10px;
	
  	
  width:	
  300px;
}
@shayhoweModular HTML & CSS
CREATE ADAPTABLE LAYOUTS
Good
.grid-­‐4,
.grid-­‐8	
  {
	
  	
  float:	
  left;
	
  	
  margin:	
  0	
  10px;
}
.grid-­‐4	
  {
	
  	
  width:	
  300px;
}
.grid-­‐8	
  {
	
  	
  width:	
  620px;
}
@shayhoweModular HTML & CSS
ASSEMBLING LAYOUT
IN PRACTICE
http://bit.ly/modular-html-css
@shayhoweModular HTML & CSS
ACCOMMODATING
CONTENT
@shayhoweModular HTML & CSS
SEPARATE CONTENT
• Separate content from container
• Stylize content regardless of container
@shayhoweModular HTML & CSS
SEPARATE CONTENT
Bad
.alert	
  {
	
  	
  background:	
  #f2dede;
	
  	
  border-­‐radius:	
  10px;
	
  	
  color:	
  #b94a48;
	
  	
  padding:	
  10px	
  20px;
}
<div	
  class="alert">...</div>
@shayhoweModular HTML & CSS
SEPARATE CONTENT
Good
.alert	
  {
	
  	
  border-­‐radius:	
  10px;
	
  	
  padding:	
  10px	
  20px;
}
.alert-­‐error	
  {
	
  	
  background:	
  #f2dede;
	
  	
  color:	
  #b94a48;
}
<div	
  class="alert	
  alert-­‐error">...</div>
@shayhoweModular HTML & CSS
AVOID PARENT DEPENDENCY
• Remove parent container dependency
• Decouple CSS from HTML
• Create components to be used anywhere
@shayhoweModular HTML & CSS
AVOID PARENT DEPENDENCY
Bad
.feat-­‐box	
  {
	
  	
  background:	
  #eee;
}
article	
  .feat-­‐box	
  {
	
  	
  background:	
  #fff;
}
<article>
	
  	
  <div	
  class="feat-­‐box">...</div>
</article>
@shayhoweModular HTML & CSS
AVOID PARENT DEPENDENCY
Good
.feat-­‐box	
  {
	
  	
  background:	
  #eee;
}
.feat-­‐box-­‐alt	
  {
	
  	
  background:	
  #fff;
}
<article>
	
  	
  <div	
  class="feat-­‐box-­‐alt">...</div>
</article>
@shayhoweModular HTML & CSS
FAVOR SEMANTICS
• Allow elements to adapt
• Uses individual classes to extend modules
@shayhoweModular HTML & CSS
FAVOR SEMANTICS
Bad
.feat-­‐box	
  h2	
  {
	
  	
  color:	
  #f60;
	
  	
  font:	
  18px	
  Helvetica,	
  sans-­‐serif;
}
<div	
  class="feat-­‐box">
	
  	
  <h2>...</h2>
</div>
@shayhoweModular HTML & CSS
FAVOR SEMANTICS
Good
.feat-­‐subhead	
  {
	
  	
  color:	
  #f60;
	
  	
  font:	
  18px	
  Helvetica,	
  sans-­‐serif;
}
<div	
  class="feat-­‐box">
	
  	
  <h2	
  class="feat-­‐subhead">...</h2>
</div>
@shayhoweModular HTML & CSS
ACCOMMODATING CONTENT
IN PRACTICE
http://bit.ly/modular-html-css
@shayhoweModular HTML & CSS
ONWARD
Ships on the Roadstead by Willem van de Velde the Younger
@shayhoweModular HTML & CSS
APPROACH
• Stop thinking about pages
• Start thinking about components
• Take visual inventory
@shayhoweModular HTML & CSS
THEMES
• Decouple HTML and CSS
• Separate presentation from layout
• Separate content from container
• Extend elements with classes
@shayhoweModular HTML & CSS
OUTCOMES
• Maintainability!
• Reusable code, less duplication
• Flexibility and extensibility
• Improved standards
@shayhoweModular HTML & CSS
WHAT’S NEXT
Build a styleguide
• Twitter Bootstrap, Zurb Foundation
Review methodologies
• OOCSS, SMACSS
Test your code
• CSS Lint, Inspector, PageSpeed
@shayhoweModular HTML & CSS
THANK YOU!
Questions?
@shayhowe
http://learn.shayhowe.com

More Related Content

What's hot (20)

PPTX
Rapid and Responsive - UX to Prototype with Bootstrap
Josh Jeffryes
 
PDF
Code &amp; design your first website (3:16)
Thinkful
 
PPTX
Web 102 INtro to CSS
Hawkman Academy
 
PDF
HTML5, just another presentation :)
François Massart
 
PDF
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
 
PDF
Code & Design your first website 4/18
TJ Stalcup
 
ZIP
Html5 public
doodlemoonch
 
PDF
CSS Frameworks
Mike Crabb
 
PPTX
Blog HTML example for IML 295
Evan Hughes
 
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
PDF
The Future Of CSS
Andy Budd
 
PDF
CSS pattern libraries
Russ Weakley
 
PDF
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
PDF
Html5 ux london
Todd Zaki Warfel
 
PDF
Progressive Prototyping w/HTML5, CSS3 and jQuery
Todd Zaki Warfel
 
PDF
CSS - OOCSS, SMACSS and more
Russ Weakley
 
PPTX
Introduction to HTML5
Terry Ryan
 
PDF
Quality Development with CSS3
Shay Howe
 
PDF
Intro to CSS
Randy Oest II
 
PPTX
HTML/CSS Web Blog Example
Michael Bodie
 
Rapid and Responsive - UX to Prototype with Bootstrap
Josh Jeffryes
 
Code &amp; design your first website (3:16)
Thinkful
 
Web 102 INtro to CSS
Hawkman Academy
 
HTML5, just another presentation :)
François Massart
 
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
 
Code & Design your first website 4/18
TJ Stalcup
 
Html5 public
doodlemoonch
 
CSS Frameworks
Mike Crabb
 
Blog HTML example for IML 295
Evan Hughes
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
The Future Of CSS
Andy Budd
 
CSS pattern libraries
Russ Weakley
 
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
Html5 ux london
Todd Zaki Warfel
 
Progressive Prototyping w/HTML5, CSS3 and jQuery
Todd Zaki Warfel
 
CSS - OOCSS, SMACSS and more
Russ Weakley
 
Introduction to HTML5
Terry Ryan
 
Quality Development with CSS3
Shay Howe
 
Intro to CSS
Randy Oest II
 
HTML/CSS Web Blog Example
Michael Bodie
 

Similar to Modular HTML & CSS Workshop (20)

PDF
Modular HTML & CSS Turbo Workshop
Shay Howe
 
PDF
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Li-Wei Lu
 
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
PPTX
Class15
Jiyeon Lee
 
PDF
HTML5 & CSS3 Flag
Christopher Schmitt
 
PDF
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 
PDF
Source Ordered Templates - - Joomla!Days NL 2009 #jd09nl
Joomla!Days Netherlands
 
PPTX
Css intro
Julia Vi
 
PDF
The Future of CSS
elliando dias
 
PDF
Future-proof styling in Drupal (8)
Hajas Tamás
 
PDF
Be nice to your designers
Pai-Cheng Tao
 
PDF
Implementing Awesome: An HTML5/CSS3 Workshop
Shoshi Roberts
 
PDF
Fewd week2 slides
William Myers
 
PDF
CSS workshop @ OutSystems
Ruben Goncalves
 
PPT
Pertemuan 7
beiharira
 
PPTX
Css for Development
tsengsite
 
PPTX
HTML5 for ASP.NET Developers
Justin Lee
 
PPT
Css week10 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
PDF
HTML5 y CSS3
InterGraphicDESIGNS
 
Modular HTML & CSS Turbo Workshop
Shay Howe
 
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Li-Wei Lu
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
Class15
Jiyeon Lee
 
HTML5 & CSS3 Flag
Christopher Schmitt
 
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 
Source Ordered Templates - - Joomla!Days NL 2009 #jd09nl
Joomla!Days Netherlands
 
Css intro
Julia Vi
 
The Future of CSS
elliando dias
 
Future-proof styling in Drupal (8)
Hajas Tamás
 
Be nice to your designers
Pai-Cheng Tao
 
Implementing Awesome: An HTML5/CSS3 Workshop
Shoshi Roberts
 
Fewd week2 slides
William Myers
 
CSS workshop @ OutSystems
Ruben Goncalves
 
Pertemuan 7
beiharira
 
Css for Development
tsengsite
 
HTML5 for ASP.NET Developers
Justin Lee
 
Css week10 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
HTML5 y CSS3
InterGraphicDESIGNS
 
Ad

More from Shay Howe (9)

PDF
Yes, Designer, You CAN Be a Product Leader
Shay Howe
 
PDF
Collaboration Practices
Shay Howe
 
PDF
How Constraints Cultivate Growth
Shay Howe
 
PDF
UI Design with HTML5 & CSS3
Shay Howe
 
PDF
HTML5 Semantics
Shay Howe
 
PDF
An Intro to HTML & CSS
Shay Howe
 
PDF
Quality Development with HTML5
Shay Howe
 
PDF
The Web Design Process: A Strategy for Success
Shay Howe
 
PDF
Writing for the Web: The Right Strategy
Shay Howe
 
Yes, Designer, You CAN Be a Product Leader
Shay Howe
 
Collaboration Practices
Shay Howe
 
How Constraints Cultivate Growth
Shay Howe
 
UI Design with HTML5 & CSS3
Shay Howe
 
HTML5 Semantics
Shay Howe
 
An Intro to HTML & CSS
Shay Howe
 
Quality Development with HTML5
Shay Howe
 
The Web Design Process: A Strategy for Success
Shay Howe
 
Writing for the Web: The Right Strategy
Shay Howe
 
Ad

Recently uploaded (20)

PPTX
Great_Discoverers_Nohzyxyxyzyzyzyzzyz_Imagptx
kevadiyahem07
 
PPTX
DEVELOPING-PARAGRAPHS.pptx-developing...
rania680036
 
DOCX
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
PDF
Design Social Change Creating Social Change
Eduardo Corrêa
 
PDF
cs603 ppts .pdf 222222222222222222222222
RabiaNazneen1
 
PPTX
Adobe Creative Cloud Cleaner Tool Crack Free Download Latest Version 2025
Slideshare
 
PPTX
Dndnnnssjsjjsjsjjsssjsjsjjsjsjsjsjjsjsjdn.pptx
Nandy31
 
PDF
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
PDF
Presentation - Interior Design Concepts (2).pdf
vrindagrawal456
 
PDF
Plastic Foam as eco-friendly product in interiors
Disha Agrawal
 
PPTX
CompanyReviewTypeOfPowerpointThatIsColor
plukleomarigpuara
 
PPTX
the very teaching plan extra ordinary.pptx
PamelaOdibeli1
 
DOCX
CERT HERNANDEZ CHURCH PHILIPPIBNES .docx
michael patino
 
PPTX
一比一原版(HM毕业证书)慕尼黑应用技术大学毕业证如何办理
Taqyea
 
DOCX
Redefining Master Plans for creating sustainable cities-Jharkhand Conference...
JIT KUMAR GUPTA
 
PPTX
feminist gnsudnshxujenduxhsixisjxuu.pptx
rowvinafujimoto
 
PPTX
Urban design is a huge concept when it comes to planning.
IshikaPanchal11
 
PPTX
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
PPTX
Adjective..pptxujjjjjjjjjjjjjjjjjjjjjjjj
seemanodiyal
 
PPTX
hall ppt 1 it for basic tamolet .pptx
ashishbehera64
 
Great_Discoverers_Nohzyxyxyzyzyzyzzyz_Imagptx
kevadiyahem07
 
DEVELOPING-PARAGRAPHS.pptx-developing...
rania680036
 
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
Design Social Change Creating Social Change
Eduardo Corrêa
 
cs603 ppts .pdf 222222222222222222222222
RabiaNazneen1
 
Adobe Creative Cloud Cleaner Tool Crack Free Download Latest Version 2025
Slideshare
 
Dndnnnssjsjjsjsjjsssjsjsjjsjsjsjsjjsjsjdn.pptx
Nandy31
 
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
Presentation - Interior Design Concepts (2).pdf
vrindagrawal456
 
Plastic Foam as eco-friendly product in interiors
Disha Agrawal
 
CompanyReviewTypeOfPowerpointThatIsColor
plukleomarigpuara
 
the very teaching plan extra ordinary.pptx
PamelaOdibeli1
 
CERT HERNANDEZ CHURCH PHILIPPIBNES .docx
michael patino
 
一比一原版(HM毕业证书)慕尼黑应用技术大学毕业证如何办理
Taqyea
 
Redefining Master Plans for creating sustainable cities-Jharkhand Conference...
JIT KUMAR GUPTA
 
feminist gnsudnshxujenduxhsixisjxuu.pptx
rowvinafujimoto
 
Urban design is a huge concept when it comes to planning.
IshikaPanchal11
 
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
Adjective..pptxujjjjjjjjjjjjjjjjjjjjjjjj
seemanodiyal
 
hall ppt 1 it for basic tamolet .pptx
ashishbehera64
 

Modular HTML & CSS Workshop

  • 1. TACTICAL HTML & CSS Shay Howe @shayhowe learn.shayhowe.com MODULAR HTML & CSS WORKSHOP
  • 2. @shayhoweModular HTML & CSS Shay Howe @shayhowe learn.shayhowe.com
  • 3. @shayhoweModular HTML & CSS 1. The Problem 2. Groundwork 3. Assembling Layout 4. Accommodating Content 5. Onward OUR SCHEDULE
  • 4. @shayhoweModular HTML & CSS THE PROBLEM
  • 5. The Gust by Willem van de Velde the Younger
  • 6. @shayhoweModular HTML & CSS COMMON PROBLEMS • Websites have difficulty scaling • Code becomes brittle • Files and code bases begin to swell
  • 7. @shayhoweModular HTML & CSS WHAT’S WRONG • Best practices aren’t exactly best practices • Standards need to evolve
  • 8. @shayhoweModular HTML & CSS BEST BAD PRACTICES • Avoid extra elements • Avoid classes • Leverage type selectors • Leverage descendent selectors
  • 9. @shayhoweModular HTML & CSS BEST BAD PRACTICES Avoiding classes section  ul#nav  li  {...} section:nth-­‐child(2)  div:nth-­‐child(7)  >  a  {...} Leveraging selectors a.btn  {...} #main  a.btn  {...} #main  div.feature  a.btn  {...}
  • 10. @shayhoweModular HTML & CSS BEST BAD PRACTICES Bad #contact  li:nth-­‐child(1)  input, #contact  li:nth-­‐child(2)  input  {    width:  160px; } #contact  li:nth-­‐child(3)  textarea  {    width:  280px; }
  • 11. @shayhoweModular HTML & CSS BEST BAD PRACTICES Good .col-­‐1  {    width:  160px; } .col-­‐2  {    width:  280px; }
  • 12. @shayhoweModular HTML & CSS SPECIFICITY? • Specificity determines which styles are applied • Each selector has a specificity weight • High specificity beats low specificity • Low specificity is key
  • 13. @shayhoweModular HTML & CSS MEASURING SPECIFICITY Formula • IDs, Classes/Pseudo-classes/Attributes, Elements High Specificity (Bad) #primary  #main  div.gallery  figure.media IDs: 2, Classes: 2, Elements: 2 — Compiled: 2–2–2 Low Specificity (Good) .gallery-­‐media IDs: 0, Classes: 1, Elements: 0 — Compiled: 0–1–0
  • 15. @shayhoweModular HTML & CSS WATCH SPECIFICITY • Be explicit • Keep specificity low • Never use IDs or !important • Avoid nested selectors (#main  .spotlight  strong  span)
  • 16. @shayhoweModular HTML & CSS WATCH SPECIFICITY Bad #primary  #main  div.gallery  {    text-­‐transform:  uppercase; } #primary  #main  div.gallery  figure.media  {    background:  #ccc; }
  • 17. @shayhoweModular HTML & CSS WATCH SPECIFICITY Good .gallery  {    text-­‐transform:  uppercase; } .gallery-­‐media  {    background:  #ccc; }
  • 18. Parade of the Black Sea Fleet by Ivan Aivazovsky
  • 19. @shayhoweModular HTML & CSS MAINTAINABILITY Code must be... • Organized • Modular • Performant
  • 20. @shayhoweModular HTML & CSS METHODOLOGIES OOCSS • Object-Oriented CSS From Nicole Sullivan – oocss.org SMACSS • Scalable and Modular Architecture for CSS From Jonathan Snook – smacss.com
  • 21. @shayhoweModular HTML & CSS GROUNDWORK
  • 22. @shayhoweModular HTML & CSS REUSE CODE • Do not duplicate code • Remove old code • Defer loading subsequent styles
  • 23. @shayhoweModular HTML & CSS REUSE CODE Bad .news  {    background:  #eee;    color:  #666; } .social  {    background:  #eee;    color:  #666; }
  • 24. @shayhoweModular HTML & CSS REUSE CODE Good .news, .social  {    background:  #eee;    color:  #666; } Better .feat-­‐box  {    background:  #eee;    color:  #666; }
  • 25. @shayhoweModular HTML & CSS USE CLASSES • Write understandable class names • Avoid unnecessary nesting • Use same strength specificity
  • 26. @shayhoweModular HTML & CSS USE CLASSES Bad .feat-­‐box  .callout  .pr  {    font-­‐size:  12px; } .feat-­‐box  .callout  .pr  .un  {    color:  #39f; }
  • 27. @shayhoweModular HTML & CSS USE CLASSES Good .feat-­‐box  .price  {    font-­‐size:  12px; } .feat-­‐box  .unit  {    color:  #39f; }
  • 28. @shayhoweModular HTML & CSS USE CLASSES Bad .btn.large  {    font-­‐size:  24px;        padding:  15px  30px; } <div  class="btn  large">...</div>
  • 29. @shayhoweModular HTML & CSS USE CLASSES Good .btn-­‐large  {    font-­‐size:  24px;    padding:  15px  30px; } <div  class="btn-­‐large">...</div>
  • 30. @shayhoweModular HTML & CSS ASSEMBLING LAYOUT
  • 31. @shayhoweModular HTML & CSS ABSTRACT STRUCTURE • Separate presentation (or theme) from layout • Create an object layer for layout • Create a skin layer for theme • Use a grid
  • 32. @shayhoweModular HTML & CSS ABSTRACT STRUCTURE Bad .news  {    background:  #eee;    color:  #666;    margin:  0  10px;    width:  400px; } <div  class="news">...</div>
  • 33. @shayhoweModular HTML & CSS ABSTRACT STRUCTURE Good .grid-­‐4  {    margin:  0  10px;    width:  400px; } .feat-­‐box  {    background:  #eee;    color:  #666; } <div  class="grid-­‐4  feat-­‐box">...</div>
  • 34. @shayhoweModular HTML & CSS TRANSPARENTIZE ELEMENTS • Stylize elements to be transparent • Keep visual properties apart from layout properties
  • 35. @shayhoweModular HTML & CSS TRANSPARENTIZE ELEMENTS Bad .pagination  {    border-­‐radius:  5px;    border:  1px  solid  #eee;    margin:  0  10px;    width:  620px; } <ul  class="pagination">...</ul>
  • 36. @shayhoweModular HTML & CSS TRANSPARENTIZE ELEMENTS Good .grid-­‐8  {    margin:  0  10px;    width:  620px; } .offset-­‐box  {    border-­‐radius:  5px;    border:  1px  solid  #eee; } <ul  class="grid-­‐8  offset-­‐box">...</ul>
  • 37. @shayhoweModular HTML & CSS CREATE ADAPTABLE LAYOUTS • Height and width should be flexible • Height should extend with content • Width should extend with a grid
  • 38. @shayhoweModular HTML & CSS CREATE ADAPTABLE LAYOUTS Bad #main  {    float:  left;    margin:  0  10px;    width:  620px; } #aside  {    float:  left;    margin:  0  10px;    width:  300px; }
  • 39. @shayhoweModular HTML & CSS CREATE ADAPTABLE LAYOUTS Good .grid-­‐4, .grid-­‐8  {    float:  left;    margin:  0  10px; } .grid-­‐4  {    width:  300px; } .grid-­‐8  {    width:  620px; }
  • 40. @shayhoweModular HTML & CSS ASSEMBLING LAYOUT IN PRACTICE http://bit.ly/modular-html-css
  • 41. @shayhoweModular HTML & CSS ACCOMMODATING CONTENT
  • 42. @shayhoweModular HTML & CSS SEPARATE CONTENT • Separate content from container • Stylize content regardless of container
  • 43. @shayhoweModular HTML & CSS SEPARATE CONTENT Bad .alert  {    background:  #f2dede;    border-­‐radius:  10px;    color:  #b94a48;    padding:  10px  20px; } <div  class="alert">...</div>
  • 44. @shayhoweModular HTML & CSS SEPARATE CONTENT Good .alert  {    border-­‐radius:  10px;    padding:  10px  20px; } .alert-­‐error  {    background:  #f2dede;    color:  #b94a48; } <div  class="alert  alert-­‐error">...</div>
  • 45. @shayhoweModular HTML & CSS AVOID PARENT DEPENDENCY • Remove parent container dependency • Decouple CSS from HTML • Create components to be used anywhere
  • 46. @shayhoweModular HTML & CSS AVOID PARENT DEPENDENCY Bad .feat-­‐box  {    background:  #eee; } article  .feat-­‐box  {    background:  #fff; } <article>    <div  class="feat-­‐box">...</div> </article>
  • 47. @shayhoweModular HTML & CSS AVOID PARENT DEPENDENCY Good .feat-­‐box  {    background:  #eee; } .feat-­‐box-­‐alt  {    background:  #fff; } <article>    <div  class="feat-­‐box-­‐alt">...</div> </article>
  • 48. @shayhoweModular HTML & CSS FAVOR SEMANTICS • Allow elements to adapt • Uses individual classes to extend modules
  • 49. @shayhoweModular HTML & CSS FAVOR SEMANTICS Bad .feat-­‐box  h2  {    color:  #f60;    font:  18px  Helvetica,  sans-­‐serif; } <div  class="feat-­‐box">    <h2>...</h2> </div>
  • 50. @shayhoweModular HTML & CSS FAVOR SEMANTICS Good .feat-­‐subhead  {    color:  #f60;    font:  18px  Helvetica,  sans-­‐serif; } <div  class="feat-­‐box">    <h2  class="feat-­‐subhead">...</h2> </div>
  • 51. @shayhoweModular HTML & CSS ACCOMMODATING CONTENT IN PRACTICE http://bit.ly/modular-html-css
  • 53. Ships on the Roadstead by Willem van de Velde the Younger
  • 54. @shayhoweModular HTML & CSS APPROACH • Stop thinking about pages • Start thinking about components • Take visual inventory
  • 55. @shayhoweModular HTML & CSS THEMES • Decouple HTML and CSS • Separate presentation from layout • Separate content from container • Extend elements with classes
  • 56. @shayhoweModular HTML & CSS OUTCOMES • Maintainability! • Reusable code, less duplication • Flexibility and extensibility • Improved standards
  • 57. @shayhoweModular HTML & CSS WHAT’S NEXT Build a styleguide • Twitter Bootstrap, Zurb Foundation Review methodologies • OOCSS, SMACSS Test your code • CSS Lint, Inspector, PageSpeed
  • 58. @shayhoweModular HTML & CSS THANK YOU! Questions? @shayhowe http://learn.shayhowe.com