SlideShare a Scribd company logo
S M A C S S
設計之道
Anderson
2017.06.01
CSS is simple.
really?
What’s the problem?
p {color: red; }
Work with CSS..
Structure Naming Testing
So, what makes for good CSS?
Specificity
Scalable and Modular
Architecture for CSS
1. Style guide, not framework
2. Strike a balance between maintenance,
performance, and readability
3. Easier to test, develop, and scale
SMACSS
Categorizing CSS Rules
Base Layout Module State Theme
Rules
* Base
* Layout
* Module
* State
* Theme
Base
* Single elements
* Attribute selectors, pseudo-class..
* No need to use !important
* CSS Resets
html, body, form { margin: 0; padding: 0; }
input[type=text] { border: 1px solid #999; }
a { color: #039; }
a:hover { color: #03C; }
Layout
* Divide the page into sections
* One or more modules together
* Major layout use ID selectors, but ID selectors aren’t
necessary
* Minor or common layout use class selectors
#header, #article, #footer {
width: 960px;
margin: auto;
}
#article {
border: solid #CCC;
border-width: 1px 0 0;
}
Higher Level Layout Style
Affecting Other Layout Styles
#article {
float: left;
}
#sidebar {
float: right;
}
.l-flipped #article {
float: right;
}
.l-flipped #sidebar {
float: left;
}
Using Two Layout Styles Together
to Switch from Fruid to Fixed Layout
#article {
width: 80%;
float: left;
}
#sidebar {
width: 20%;
float: right;
}
.l-fixed #article {
width: 600px;
}
.l-fixed #sidebar {
width: 200px;
}
Module* Reusable, modular parts
A Possible Approach to Styling the
List of Featured Items
div#featured ul {
margin: 0;
padding: 0;
list-style-type: none;
}
div#featured li {
float: left;
height: 100px;
margin-left: 10px;
}
.l-grid {
margin: 0;
padding: 0;
list-style-type: none;
}
.l-grid > li {
display: inline-block;
margin: 0 0 10px 10px;
}
What’s the difference ?
Module rules
* a standalone component
* e.g navigation bars, carousels, dialogs..
* Avoid using IDs and element selectors, use class
names only
* Specificity
.module > h2 {
padding: 5px;
}
.module span {
padding: 5px;
}
[Notice] : Use child or descendant selectors if predictable
Styling with Generic Element
<div class="fld">
<span>Folder Name</span>
</div>
.fld > span {
padding-left: 20px;
background: url(icon.png);
}
Styling with Generic Element
<div class="fld">
<span>Folder Name</span>
<span>(32 items)</span>
</div>
.fld > span {
padding-left: 20px;
background: url(icon.png);
}
Styling with Generic Element
<div class="fld">
<span class="fld-name">Folder Name</span>
<span class="fld-items">(32 items)</span>
</div>
* Increased the semantics
* Removed any ambiguity
Subclassing Modules
.pod {
width: 100%;
}
.pod input[type=text] {
width: 50%;
}
#sidebar .pod input[type=text] {
width: 100%;
}
Battling against Specificity
.pod {
width: 100%;
}
.pod input[type=text] {
width: 50%;
}
#sidebar .pod input[type=text] {
width: 100%;
}
.pod-callout {
width: 200px;
}
#sidebar .pod-callout input[type=text],
.pod-callout input[type=text] {
width: 180px;
}
Battling against Specificity
.pod {
width: 100%;
}
.pod input[type=text] {
width: 50%;
}
.pod-constrained input[type=text] {
width: 100%;
}
.pod-callout {
width: 200px;
}
.pod-callout input[type=text] {
width: 180px;
}
Sub-module Class Name in HTML
<div class="pod pod-constrained">...</div>
<div class="pod pod-callout">...</div>
* Load base first, then overwriting by sub-class
State
* JavaScript dependency
* Apply to layout and/or module styles
* How our modules or layouts will look
when in a particular state
* Use of !important is allowed
State applied to an element
<div id="header" class="is-collapsed">
<form>
<div class="msg is-error">
There is an error!
</div>
<label
for="searchbox"
class="is-hidden">
Search
</label>
<input type="search" id="searchbox">
</form>
</div>
Combining State Rules
with Modules
.tab {
background-color: purple;
color: white;
}
.is-tab-active {
background-color: white;
color: black;
}
Theme
* Aren’t used as often
* Fonts
* Based on locale such as
country or language
/* in theme.css */
.theme-border {
border-color: purple;
}
.theme-background {
background: linear-gradient( ... );
}
State changes
* Class name
* Change happens with
JavaScript
* Pseudo-class:
* Don't use by javascript,
limited in elements that are
descendants or siblings of the
element
* Media query
JavaScript changing state
via class name
$('.btn-close').click(function(){
$(this).parents('.dialog').addClass('is-
hidden');
})
Loading Menu with jQuery
$('#btn-new').click(function(){
var el = $(this);
el.addClass('is-pressed');
$('#menu-' +
el.id.substr(4)).removeClass('is-hidden');
});
Adding a Class to Parent Element
to Style Child Elements
<div id="content">
<div class="toolbar is-active">
<button id="btn-new" class="btn"
data-action="menu">New</button>
<div id="menu-new" class="menu">
<ul> ... </ul>
</div>
</div>
</div>
.is-active .btn { color: #000; }
.is-active .menu { display: block; }
Activating the Menu
with a Sibling Selector
<div id="content">
<div class="toolbar">
<button
id="btn-new"
class="btn is-active"
data-action="menu">
New
</button>
<div id="menu-new" class="menu">
<ul> ... </ul>
</div>
</div>
</div>
.btn.is-active { color: #000; }
.btn.is-active + .menu { display: block; }
Why Parent and Sibling States
are Problematic
* Applying a state to each module is that it is no longer
clear where this rule set should go
* Applying a state to each button is the preferred
approach
Handling State Change with
Attribute Selectors
* Isolating states from layout and module classes
* Allowing easier transitions between multiple states
Attribute selectors convention
.btn[data-state=default] { color: #333; }
.btn[data-state=pressed] { color: #000; }
.btn[data-state=disabled] { opacity: .5; pointer-
events: none; }
<button class="btn"
data-state=“disabled">Disabled</button>
$(".btn").bind("click", function(){
$(this).attr('data-state', 'pressed');
});
Animations in
current browsers
@-webkit-keyframes fade {
0% { opacity:0; }
100% { opacity:1; display:block; }
}
.is-visible {
opacity: 1;
animation: fade 2s;
}
.is-hidden {
opacity: 0;
animation: fade 2s reverse;
}
.is-removed {
display: none;
}
function showMessage (s) {
var el = document.
getElementById('message');
el.innerHTML = s;
el.className = 'is-visible';
setTimeout(function(){
el.className = 'is-hidden';
setTimeout(function(){
el.className = 'is-removed';
}, 2000);
}, 3000);
}
Defining States with
Pseudo-classes
.btn {
background-color: #333; /* gray */
}
.btn:hover {
background-color: #336; /* blueish */
}
.btn:focus {
/* blueish focus ring */
box-shadow: 0 0 3px rgba(48,48,96,.3);
}
Sub-module States
with Pseudo-classes
.btn {
background-color: #333; /* gray */
}
.btn:hover {
background-color: #336; /* blueish */
}
.btn:focus {
box-shadow: 0 0 3px rgba(48,48,96,.3);
}
.btn-default {
background-color: #DEDB12; /* yellowish */
}
.btn-default:hover {
background-color: #B8B50B; /* darker yellow */
}
Modules, Sub-modules,
Class States
and Pseudo-class States
.btn { ... }
.btn:hover { ... }
.btn:focus { ... }
.btn-default { ... }
.btn-default:hover { ... }
.btn.is-pressed { ... }
.btn.is-pressed:hover { ... }
.btn-default.is-pressed { ... }
.btn-default.is-pressed:hover { ... }
Modular Media Queries
/* default state for nav items */
.nav > li {
float: left;
}
/* alternate state for nav items on small screens
*/
@media screen and (max-width: 400px) {
.nav > li { float: none; }
}
Demo
Performance
* Performance Tool
* Depth of Applicability
* How CSS gets evaluated
* HTML5 and SMACSS
* Prototyping
* Formatting Code
Performance Tool
* Goolge page-speed tool
* Think with Google
Depth of Applicability
#sidebar div, #footer div {
border: 1px solid #333;
}
#sidebar div h3, #footer div h3 {
margin-top: 5px;
}
#sidebar div ul, #footer div ul {
margin-bottom: 5px;
}
* Minimizing the Depth
* e.g body.article > #main > #content > #intro > p > b
* e.g .article #intro b
.pod {
border: 1px solid #333;
}
.pod > h3 {
margin-top: 5px;
}
.pod > ul {
margin-bottom: 5px;
}
How CSS Gets Evaluated
body div#content p { color: #003366; }
* Evaluated on element creation (CSS flow)
* Evaluated from right to left
Which is Inefficient
* Rules with descendant selectors
* e.g. #content h3
* Rules with child or adjacent selectors
* e.g. #content > h3
* Rules with overly qualified selectors
* e.g. div#content > h3
* Rules that apply :hover to non-link elements.
* e.g. div#content:hover
Selector Performance
<p class="bodytext">
* No more than a single element to determine styling is
inefficient
Constrain yourself,
don’t choke yourself
* Use child selectors
* Avoid tag selectors for common elements
* Use class names as the right-most selector
HTML5 and SMACSS
* Increase the semantic value of a section of HTML and
content
<nav> Implementation
<nav class="nav-primary">
<h1>Primary Navigation</h1>
<ul>…</ul>
</nav>
<nav class="nav-secondary">
<h1>External Links</h1>
<ul>…</ul>
</nav>
nav.nav-primary li {
display: inline-block;
}
nav.nav-secondary li {
display: block;
}
Add Dropdown to Every Element
<nav class="nav-primary">
<h1>Primary Navigation</h1>
<ul>
<li>About Us
<ul>
<li>Team</li>
<li>Location</li>
</ul>
</li>
</ul>
</nav>
Augmented <nav> CSS
nav.nav-primary li {
display: inline-block;
}
nav.nav-secondary li,
nav.nav-primary li li {
display: block;
}
In SMACSS-style
.l-inline > * {
display: inline-block;
}
.l-stacked > * {
display: block;
}
<nav class="l-inline">
<h1>Primary Navigation</h1>
<ul>
<li>About Us
<ul class="l-stacked">
<li>Team</li>
<li>Location</li>
</ul>
</li>
</ul>
</nav>
Prototyping
* Has some sample to follow
* Show states
* Review localization
* Isolate dependencies
Formatting Code
* Colour Declarations
* Grouping Properties
* 1. Box: display, float, position, left, top, height...
* 2. Border
* 3. Background
* 4. Text
* 5. Other
T H A N K
YOU

More Related Content

What's hot

Jina Bolton
Jina BoltonJina Bolton
Jina Bolton
Carsonified Team
 
Try Web Components
Try Web ComponentsTry Web Components
Try Web Components
拓樹 谷
 
Html bangla
Html banglaHtml bangla
Html bangla
bhorerpakhi
 
Bangla html
Bangla htmlBangla html
Bangla html
Shopnomoy Prantor
 
Python Templating Engine - Intro to Jinja
Python Templating Engine - Intro to JinjaPython Templating Engine - Intro to Jinja
Python Templating Engine - Intro to Jinja
Eueung Mulyana
 
Web Developement Workshop (Oct 2009) Slides
Web Developement Workshop (Oct 2009) SlidesWeb Developement Workshop (Oct 2009) Slides
Web Developement Workshop (Oct 2009) Slides
Manish Sinha
 
Synapse india basic php development part 2
Synapse india basic php development part 2Synapse india basic php development part 2
Synapse india basic php development part 2
Synapseindiappsdevelopment
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSS
Max Kraszewski
 
Just css results dogmeat template validator
Just css results dogmeat template validatorJust css results dogmeat template validator
Just css results dogmeat template validator
Gaejang Guk
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013
Sébastien Deleuze
 

What's hot (10)

Jina Bolton
Jina BoltonJina Bolton
Jina Bolton
 
Try Web Components
Try Web ComponentsTry Web Components
Try Web Components
 
Html bangla
Html banglaHtml bangla
Html bangla
 
Bangla html
Bangla htmlBangla html
Bangla html
 
Python Templating Engine - Intro to Jinja
Python Templating Engine - Intro to JinjaPython Templating Engine - Intro to Jinja
Python Templating Engine - Intro to Jinja
 
Web Developement Workshop (Oct 2009) Slides
Web Developement Workshop (Oct 2009) SlidesWeb Developement Workshop (Oct 2009) Slides
Web Developement Workshop (Oct 2009) Slides
 
Synapse india basic php development part 2
Synapse india basic php development part 2Synapse india basic php development part 2
Synapse india basic php development part 2
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSS
 
Just css results dogmeat template validator
Just css results dogmeat template validatorJust css results dogmeat template validator
Just css results dogmeat template validator
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013
 

Similar to CSS- Smacss Design Rule

Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
William Myers
 
Start your app the better way with Styled System
Start your app the better way with Styled SystemStart your app the better way with Styled System
Start your app the better way with Styled System
Hsin-Hao Tang
 
Css3
Css3Css3
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
Ardee Aram
 
CSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI DevelopersCSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI Developers
Darren Gideon
 
Css3
Css3Css3
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
Tim Hettler
 
The Future State of Layout
The Future State of LayoutThe Future State of Layout
The Future State of Layout
Stephen Hay
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
Hatem Mahmoud
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
Arash Manteghi
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
raghavanp4
 
css.ppt
css.pptcss.ppt
css.ppt
css.pptcss.ppt
css.ppt
Sana903754
 
World of CSS Grid
World of CSS GridWorld of CSS Grid
World of CSS Grid
Elad Shechter
 
CSS
CSSCSS
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
SoniaJoshi25
 
Introduction to CSS Grid
Introduction to CSS GridIntroduction to CSS Grid
Introduction to CSS Grid
Kara Luton
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
Tesfaye Yenealem
 

Similar to CSS- Smacss Design Rule (20)

Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Start your app the better way with Styled System
Start your app the better way with Styled SystemStart your app the better way with Styled System
Start your app the better way with Styled System
 
Css3
Css3Css3
Css3
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
CSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI DevelopersCSS101 - Concept Fundamentals for non UI Developers
CSS101 - Concept Fundamentals for non UI Developers
 
Css3
Css3Css3
Css3
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
The Future State of Layout
The Future State of LayoutThe Future State of Layout
The Future State of Layout
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
World of CSS Grid
World of CSS GridWorld of CSS Grid
World of CSS Grid
 
CSS
CSSCSS
CSS
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
 
Introduction to CSS Grid
Introduction to CSS GridIntroduction to CSS Grid
Introduction to CSS Grid
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 

Recently uploaded

UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptxUNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
GOWSIKRAJA PALANISAMY
 
Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1
Decomart Studio
 
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
asuzyq
 
一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理
peuce
 
Revolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in IndiaRevolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in India
amrsoftec1
 
NHR Engineers Portfolio 2023 2024 NISHANT RATHI
NHR Engineers Portfolio 2023 2024 NISHANT RATHINHR Engineers Portfolio 2023 2024 NISHANT RATHI
NHR Engineers Portfolio 2023 2024 NISHANT RATHI
NishantRathi18
 
Mohannad Abdullah portfolio _ V2 _22-24
Mohannad Abdullah  portfolio _ V2 _22-24Mohannad Abdullah  portfolio _ V2 _22-24
Mohannad Abdullah portfolio _ V2 _22-24
M. A. Architect
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
kecekev
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
Bianca Woods
 
定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样
qo1as76n
 
PDF SubmissionDigital Marketing Institute in Noida
PDF SubmissionDigital Marketing Institute in NoidaPDF SubmissionDigital Marketing Institute in Noida
PDF SubmissionDigital Marketing Institute in Noida
PoojaSaini954651
 
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdfSECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
eloprejohn333
 
Divertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8djDivertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8dj
lunaemel03
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
pmgdscunsri
 
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With DesignsGame Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
184804
 
Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.
Techno Merch
 
Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
Carolina de Bartolo
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
talaatahm
 
Branding de la empresa de Bolt- 2024.pdf
Branding de la empresa de Bolt- 2024.pdfBranding de la empresa de Bolt- 2024.pdf
Branding de la empresa de Bolt- 2024.pdf
PabloMartelLpez
 

Recently uploaded (20)

UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptxUNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
 
Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1
 
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
 
一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理
 
Revolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in IndiaRevolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in India
 
NHR Engineers Portfolio 2023 2024 NISHANT RATHI
NHR Engineers Portfolio 2023 2024 NISHANT RATHINHR Engineers Portfolio 2023 2024 NISHANT RATHI
NHR Engineers Portfolio 2023 2024 NISHANT RATHI
 
Mohannad Abdullah portfolio _ V2 _22-24
Mohannad Abdullah  portfolio _ V2 _22-24Mohannad Abdullah  portfolio _ V2 _22-24
Mohannad Abdullah portfolio _ V2 _22-24
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
 
定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样
 
PDF SubmissionDigital Marketing Institute in Noida
PDF SubmissionDigital Marketing Institute in NoidaPDF SubmissionDigital Marketing Institute in Noida
PDF SubmissionDigital Marketing Institute in Noida
 
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdfSECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
 
Divertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8djDivertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8dj
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
 
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With DesignsGame Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
 
Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.
 
Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
 
Branding de la empresa de Bolt- 2024.pdf
Branding de la empresa de Bolt- 2024.pdfBranding de la empresa de Bolt- 2024.pdf
Branding de la empresa de Bolt- 2024.pdf
 

CSS- Smacss Design Rule

  • 1. S M A C S S 設計之道 Anderson 2017.06.01
  • 2.
  • 4. What’s the problem? p {color: red; }
  • 6. Structure Naming Testing So, what makes for good CSS? Specificity
  • 7. Scalable and Modular Architecture for CSS 1. Style guide, not framework 2. Strike a balance between maintenance, performance, and readability 3. Easier to test, develop, and scale SMACSS
  • 8. Categorizing CSS Rules Base Layout Module State Theme
  • 9.
  • 10. Rules * Base * Layout * Module * State * Theme
  • 11. Base * Single elements * Attribute selectors, pseudo-class.. * No need to use !important * CSS Resets html, body, form { margin: 0; padding: 0; } input[type=text] { border: 1px solid #999; } a { color: #039; } a:hover { color: #03C; }
  • 12. Layout * Divide the page into sections * One or more modules together * Major layout use ID selectors, but ID selectors aren’t necessary * Minor or common layout use class selectors #header, #article, #footer { width: 960px; margin: auto; } #article { border: solid #CCC; border-width: 1px 0 0; }
  • 13. Higher Level Layout Style Affecting Other Layout Styles #article { float: left; } #sidebar { float: right; } .l-flipped #article { float: right; } .l-flipped #sidebar { float: left; }
  • 14. Using Two Layout Styles Together to Switch from Fruid to Fixed Layout #article { width: 80%; float: left; } #sidebar { width: 20%; float: right; } .l-fixed #article { width: 600px; } .l-fixed #sidebar { width: 200px; }
  • 16. A Possible Approach to Styling the List of Featured Items div#featured ul { margin: 0; padding: 0; list-style-type: none; } div#featured li { float: left; height: 100px; margin-left: 10px; } .l-grid { margin: 0; padding: 0; list-style-type: none; } .l-grid > li { display: inline-block; margin: 0 0 10px 10px; } What’s the difference ?
  • 17. Module rules * a standalone component * e.g navigation bars, carousels, dialogs.. * Avoid using IDs and element selectors, use class names only * Specificity .module > h2 { padding: 5px; } .module span { padding: 5px; } [Notice] : Use child or descendant selectors if predictable
  • 18. Styling with Generic Element <div class="fld"> <span>Folder Name</span> </div> .fld > span { padding-left: 20px; background: url(icon.png); }
  • 19. Styling with Generic Element <div class="fld"> <span>Folder Name</span> <span>(32 items)</span> </div> .fld > span { padding-left: 20px; background: url(icon.png); }
  • 20. Styling with Generic Element <div class="fld"> <span class="fld-name">Folder Name</span> <span class="fld-items">(32 items)</span> </div> * Increased the semantics * Removed any ambiguity
  • 21. Subclassing Modules .pod { width: 100%; } .pod input[type=text] { width: 50%; } #sidebar .pod input[type=text] { width: 100%; }
  • 22. Battling against Specificity .pod { width: 100%; } .pod input[type=text] { width: 50%; } #sidebar .pod input[type=text] { width: 100%; } .pod-callout { width: 200px; } #sidebar .pod-callout input[type=text], .pod-callout input[type=text] { width: 180px; }
  • 23. Battling against Specificity .pod { width: 100%; } .pod input[type=text] { width: 50%; } .pod-constrained input[type=text] { width: 100%; } .pod-callout { width: 200px; } .pod-callout input[type=text] { width: 180px; }
  • 24. Sub-module Class Name in HTML <div class="pod pod-constrained">...</div> <div class="pod pod-callout">...</div> * Load base first, then overwriting by sub-class
  • 25. State * JavaScript dependency * Apply to layout and/or module styles * How our modules or layouts will look when in a particular state * Use of !important is allowed
  • 26. State applied to an element <div id="header" class="is-collapsed"> <form> <div class="msg is-error"> There is an error! </div> <label for="searchbox" class="is-hidden"> Search </label> <input type="search" id="searchbox"> </form> </div>
  • 27. Combining State Rules with Modules .tab { background-color: purple; color: white; } .is-tab-active { background-color: white; color: black; }
  • 28. Theme * Aren’t used as often * Fonts * Based on locale such as country or language /* in theme.css */ .theme-border { border-color: purple; } .theme-background { background: linear-gradient( ... ); }
  • 29. State changes * Class name * Change happens with JavaScript * Pseudo-class: * Don't use by javascript, limited in elements that are descendants or siblings of the element * Media query
  • 30. JavaScript changing state via class name $('.btn-close').click(function(){ $(this).parents('.dialog').addClass('is- hidden'); })
  • 31. Loading Menu with jQuery $('#btn-new').click(function(){ var el = $(this); el.addClass('is-pressed'); $('#menu-' + el.id.substr(4)).removeClass('is-hidden'); });
  • 32. Adding a Class to Parent Element to Style Child Elements <div id="content"> <div class="toolbar is-active"> <button id="btn-new" class="btn" data-action="menu">New</button> <div id="menu-new" class="menu"> <ul> ... </ul> </div> </div> </div> .is-active .btn { color: #000; } .is-active .menu { display: block; }
  • 33. Activating the Menu with a Sibling Selector <div id="content"> <div class="toolbar"> <button id="btn-new" class="btn is-active" data-action="menu"> New </button> <div id="menu-new" class="menu"> <ul> ... </ul> </div> </div> </div> .btn.is-active { color: #000; } .btn.is-active + .menu { display: block; }
  • 34. Why Parent and Sibling States are Problematic * Applying a state to each module is that it is no longer clear where this rule set should go * Applying a state to each button is the preferred approach
  • 35. Handling State Change with Attribute Selectors * Isolating states from layout and module classes * Allowing easier transitions between multiple states
  • 36. Attribute selectors convention .btn[data-state=default] { color: #333; } .btn[data-state=pressed] { color: #000; } .btn[data-state=disabled] { opacity: .5; pointer- events: none; } <button class="btn" data-state=“disabled">Disabled</button> $(".btn").bind("click", function(){ $(this).attr('data-state', 'pressed'); });
  • 37. Animations in current browsers @-webkit-keyframes fade { 0% { opacity:0; } 100% { opacity:1; display:block; } } .is-visible { opacity: 1; animation: fade 2s; } .is-hidden { opacity: 0; animation: fade 2s reverse; } .is-removed { display: none; } function showMessage (s) { var el = document. getElementById('message'); el.innerHTML = s; el.className = 'is-visible'; setTimeout(function(){ el.className = 'is-hidden'; setTimeout(function(){ el.className = 'is-removed'; }, 2000); }, 3000); }
  • 38. Defining States with Pseudo-classes .btn { background-color: #333; /* gray */ } .btn:hover { background-color: #336; /* blueish */ } .btn:focus { /* blueish focus ring */ box-shadow: 0 0 3px rgba(48,48,96,.3); }
  • 39. Sub-module States with Pseudo-classes .btn { background-color: #333; /* gray */ } .btn:hover { background-color: #336; /* blueish */ } .btn:focus { box-shadow: 0 0 3px rgba(48,48,96,.3); } .btn-default { background-color: #DEDB12; /* yellowish */ } .btn-default:hover { background-color: #B8B50B; /* darker yellow */ }
  • 40. Modules, Sub-modules, Class States and Pseudo-class States .btn { ... } .btn:hover { ... } .btn:focus { ... } .btn-default { ... } .btn-default:hover { ... } .btn.is-pressed { ... } .btn.is-pressed:hover { ... } .btn-default.is-pressed { ... } .btn-default.is-pressed:hover { ... }
  • 41. Modular Media Queries /* default state for nav items */ .nav > li { float: left; } /* alternate state for nav items on small screens */ @media screen and (max-width: 400px) { .nav > li { float: none; } }
  • 42. Demo
  • 43. Performance * Performance Tool * Depth of Applicability * How CSS gets evaluated * HTML5 and SMACSS * Prototyping * Formatting Code
  • 44. Performance Tool * Goolge page-speed tool * Think with Google
  • 45. Depth of Applicability #sidebar div, #footer div { border: 1px solid #333; } #sidebar div h3, #footer div h3 { margin-top: 5px; } #sidebar div ul, #footer div ul { margin-bottom: 5px; } * Minimizing the Depth * e.g body.article > #main > #content > #intro > p > b * e.g .article #intro b .pod { border: 1px solid #333; } .pod > h3 { margin-top: 5px; } .pod > ul { margin-bottom: 5px; }
  • 46. How CSS Gets Evaluated body div#content p { color: #003366; } * Evaluated on element creation (CSS flow) * Evaluated from right to left
  • 47. Which is Inefficient * Rules with descendant selectors * e.g. #content h3 * Rules with child or adjacent selectors * e.g. #content > h3 * Rules with overly qualified selectors * e.g. div#content > h3 * Rules that apply :hover to non-link elements. * e.g. div#content:hover
  • 48. Selector Performance <p class="bodytext"> * No more than a single element to determine styling is inefficient
  • 49. Constrain yourself, don’t choke yourself * Use child selectors * Avoid tag selectors for common elements * Use class names as the right-most selector
  • 50. HTML5 and SMACSS * Increase the semantic value of a section of HTML and content
  • 51. <nav> Implementation <nav class="nav-primary"> <h1>Primary Navigation</h1> <ul>…</ul> </nav> <nav class="nav-secondary"> <h1>External Links</h1> <ul>…</ul> </nav> nav.nav-primary li { display: inline-block; } nav.nav-secondary li { display: block; }
  • 52. Add Dropdown to Every Element <nav class="nav-primary"> <h1>Primary Navigation</h1> <ul> <li>About Us <ul> <li>Team</li> <li>Location</li> </ul> </li> </ul> </nav>
  • 53. Augmented <nav> CSS nav.nav-primary li { display: inline-block; } nav.nav-secondary li, nav.nav-primary li li { display: block; }
  • 54. In SMACSS-style .l-inline > * { display: inline-block; } .l-stacked > * { display: block; } <nav class="l-inline"> <h1>Primary Navigation</h1> <ul> <li>About Us <ul class="l-stacked"> <li>Team</li> <li>Location</li> </ul> </li> </ul> </nav>
  • 55. Prototyping * Has some sample to follow * Show states * Review localization * Isolate dependencies
  • 56. Formatting Code * Colour Declarations * Grouping Properties * 1. Box: display, float, position, left, top, height... * 2. Border * 3. Background * 4. Text * 5. Other
  • 57. T H A N K YOU