Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CSS Components
Search
Hiroki Tani
June 21, 2014
Design
15
1.9k
CSS Components
2014-06-21 Frontrend in Nagoya w/ HTML5 NAGOYA
Hiroki Tani
June 21, 2014
Tweet
Share
More Decks by Hiroki Tani
See All by Hiroki Tani
Thinking about CSS Architecture
hilokitani
0
150
Other Decks in Design
See All in Design
20241019-CUD友の会「困った!を解決するデザイン改訂版」交流会
majimasachi
0
290
開発チームの中心で心理的安全性をつくる、UXデザイナーの問いかけ方
takuto_yonemichi
2
610
ENEOS社事例|アプリ事業を加速させるデザイナーの取り組み / dx-eneos-design
cyberagentdevelopers
PRO
1
510
Slip N Slime - Character Design Ideation
thebogheart
0
340
Charcoal 2.0: デザインシステムの基盤を再構築
godlingkogami
1
550
成長する組織のナレッジベースのつくりかた_知識基盤のデザインとメタデザイン
gaussbeam
0
600
Design System for training program
mct
0
160
東急URBAN HACKSのデザイナーって何やってるの? 〜Designer Night #1〜 移動・不動産領域の取り組み
tmtgtkhs
0
160
「ちょっといいUI」を目指す努力 / Striving for Little Big Details
usagimaru
6
3.9k
Findy - デザイナー向け会社紹介 / Hiring Findy's Designers
findyinc
6
56k
Webフォント選定の極意!フォントの基本から最新トレンドまで徹底解説
takanorip
5
720
美しいUIを作るために デザイナーが意識している ちょっとした考え方
yuichi_hara7
51
33k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Fireside Chat
paigeccino
34
3.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Automating Front-end Workflow
addyosmani
1366
200k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Designing for humans not robots
tammielis
250
25k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Transcript
Beyond the CSS Architecture Components CSS
Front-end Engineer Hiroki Tani github.com/hiloki twitter.com/hiloki inkdesign.jp
CSS Mark-up
CSS Mark-up Designer ➡
CSS Mark-up Designer ➡ Engineer ⬅
CSS
Easy .text { color: red; }
Hard too #main .article { ... } #main .article .title
{ ... } #main .breaking .title { ... } #header #logo img { ... } #header li#logoTop { ... } #header li#logoTop:after { .article-header .datetime s ul.member-list li.member a .widget p,.widget ul { ... } #sidebar .widget { ... } #sidebar li a.register{} body.landing #main sectio #slider #slider-control > di
CSS Architecture
http://codepen.io/hiloki/full/dnGeB
None
<div class="speaker"> <div class="image"> <img src="tani.jpg"> </div> <div class="inner"> <p
class=“name”>…</p> <div class="biography"> <p>...</p> </div> </div> </div>
None
.speaker { overflow: hidden; /* Clearfix */ padding: 20px; background-color:
#fff; } .speaker .image { float: left; margin-right: 15px; } .speaker .image > img { border-radius: 60px; } .speaker .inner { overflow: hidden; } …
None
<div class="book"> <div class="cover"> <img src="book.jpg"> </div> <div class="inner"> <p
class="title">...</p> <p class="info"> ... </p> <div class="intro"> <p>...</p> </div> <ul class="shop"> <li>...</li> </ul> </div> </div>
None
.book { overflow: hidden; /* Clearfix */ padding: 20px; background-color:
#9DBCB8; color: #FFF; } .book .cover { float: left; margin-right: 20px; } .book .inner { overflow: hidden; } .book .title { ... } ...
None
<div class="event"> <a href="event.html"> <div class="thumbnail"> <img src="event.jpg"> </div> <div
class="inner"> <p class="event__name">...</p> </div> </a> </div>
None
.event > a { display: block; } .event .thumbnail {
float: left; margin-right: 15px; } .event .inner { overflow: hidden; } …
None
None
None
<div class="media speaker"> <div class="media__image image"> <img src="tani.jpg"> </div> <div
class="media__body inner"> <p class="name">…</p> <div class="biography"> <p>...</p> </div> </div> </div>
None
/* Media */ .media { overflow: hidden; /* Clearfix */
} .media__image { float: left; margin-right: 15px; } .media__body { overflow: hidden; }
.speaker { overflow: hidden; /* Clearfix */ padding: 20px; background-color:
#fff; } .speaker .image { float: left; margin-right: 15px; } .speaker .image > img { border-radius: 60px; } .speaker .inner { overflow: hidden; } … .speaker { overflow: hidden; /* Clearfix */ padding: 20px; background-color: #fff; } .speaker .image { float: left; margin-right: 15px; } .speaker .image > img { border-radius: 60px; } .speaker .inner { overflow: hidden; } …
.speaker { overflow: hidden; /* Clearfix */ padding: 20px; background-color:
#fff; } .speaker .image { float: left; margin-right: 15px; } .speaker .image > img { border-radius: 60px; } .speaker .inner { overflow: hidden; } …
None
.book { overflow: hidden; /* Clearfix */ padding: 20px; background-color:
#9DBCB8; color: #FFF; } .book .cover { float: left; margin-right: 20px; } .book .inner { overflow: hidden; } .book .title { ... } ...
None
.event > a { display: block; } .event .thumbnail {
float: left; margin-right: 15px; } .event .inner { overflow: hidden; } …
None
None
<div class=“media book"> <div class=“media__image book__cover”> <img src="book.jpg"> </div> <div
class=“media__body”> <p class="book__name">...</p> <p class="book__info"> ... </p> <div class="book__intro"> <p>...</p> </div> <ul class="book__shop"> <li>...</li> </ul> </div> </div>
None
.book { padding: 20px; background-color: #9DBCB8; color: #FFF; } .book__cover
{ margin-right: 20px; } .book__title { ... } ...
OOCSS Nicole Sullivan @stubbornella
OOCSS SMACSS BEM MCSS FLOCSS
CSS Components
= encapsulation Components
Not perfect Components
None
<div class="book"> <div class="book__cover"> <p class=“book__name"> … </p> </div> </div>
<div id="pickup"> <div class="book"> <div class="book__cover"> <p class="book__name"> CSS…</p>... </div>
</div> </div> <div class="book"> <div class="book__cover"> <p class=“book__name"> … </p> </div> </div>
None
#pickup .book__name { color: #111; font-size: 2em; } ! .book__name
{ margin-bottom: 10px; line-height: 1.3; font-weight: bold; font-size: 1.2em; }
☢
None
#pickup .book__name { color: #111; font-size: 2em; } ! .book__name
{ margin-bottom: 10px; line-height: 1.3; font-weight: bold; font-size: 1.2em; background-color: #333; padding: 6px; }
None
#pickup .book__name { color: #111; font-size: 2em; background-color: #FFF; padding:
0; } ! .book__name { margin-bottom: 10px; line-height: 1.3; font-weight: bold; font-size: 1.2em; background-color: #333; padding: 6px; }
<style scoped>
None
<div><!-- Scope --> <style scoped> .book__name { background-color: #333; padding:
6px; } </style> <div class=“media book"> <div class=“media__body”> <p class=“book__name”> … </p> </div> </div> </div>
<style scoped> ⛼
<style scoped> ⛼
Components
Sharable Maintainable Easily-controlled
Components Web
Web Components Templates Shadow DOM HTML Imports
Custom Elements
Templates <template id="my-media-template"> <div class="media"> <div class="media__image"> <img> </div> <div
class="media__body"> <content></content> </div> </div> </template>
Custom Elements <google-map></google-map> ! <x-calendar today></x-calendar> ! <button is="like-button"></button> !
<my-media src="tani.jpg" width="120" height="120">
Custom Elements var element = Object.create( HTMLElement.prototype ); document.registerElement( 'my-alert',
{ prototype: element } );
Shadow DOM // ΧελϜཁૉͷΠϯελϯε͕ੜ͞Εͨ࣌ʹ࣮ߦ͢Δ element.createdCallback = function() { var template
= document.querySelector('#my-media- template'); ! // templateͷDocumentFragment͔ΒcontentΛऔಘ͢Δ var content = template.content; ! // Shadow RootʹcontentΛՃ͢ΔʢShadowDOMͷܗʣ var shadowRoot = this.createShadowRoot(); shadowRoot.appendChild( document.importNode(content, true) ); };
Shadow DOM // ΧελϜཁૉͷΠϯελϯε͕ੜ͞Εͨ࣌ʹ࣮ߦ͢Δ element.createdCallback = function() { var template
= document.querySelector('#my-media- template'); ! // templateͷDocumentFragment͔ΒcontentΛऔಘ͢Δ var content = template.content; ! // Shadow RootʹcontentΛՃ͢ΔʢShadowDOMͷܗʣ var shadowRoot = this.createShadowRoot(); shadowRoot.appendChild( document.importNode(content, true) ); }; = encapsulation
HTML Imports <head> <link rel="import" href=“components/my-media.html"> </head>
Web Components Templates Shadow DOM HTML
Imports Custom Elements
http://codepen.io/hiloki/full/obFui
None
<my-media src=“sensui.jpg" width=“120" height=“120" class="speaker"> <p class=“speaker__name"> ઘਫ ᠳޗ </p>
<div class="speaker__bio"> <p>…</p> </div> </my-media>
None
<my-media src="sensui.jpg" width="120" height="120" class="speaker"> <p class=“speaker__name"> ઘਫ ᠳޗ </p>
<div class="speaker__bio"> <p>…</p> </div> </my-media>
None
<my-media src=“book.jpg" width=“100" height=“100" class="book"> <p class=“book__name"> ϑϩϯτΤϯυ… </p> <div
class=“book__info”> <p>…</p> </div> … </my-media>
None
None
<div class="media speaker"> <divclass=“media__image speaker__image”> <img src="tani.jpg" width="120"> </div> <div
class="media__body"> <p class=“speaker__name"> ୩ थ </p> ... </div> </div>
None
<my-media src=“sugimoto.jpg" width=“120" class="speaker"> <p class=“speaker__name"> ਿຊ ٢ষ </p> ...
</my-media>
None
None
<my-media src="sugimoto.jpg" width="120" class="speaker"> <div class="media"> <div class=“media__image"> <img src="tani.jpg"
width="120"> </div> <div class="media__body"> <p class="speaker__name">ਿຊ ٢ষ</p> ... </div> </div> </my-media>
None
<div class="media speaker"> <div class="media__image speaker__image"> <img src="tani.jpg" width="120"> </div>
<div class="media__body"> <p class="speaker__name">୩ थ </p> ... </div> </div>
/* <head> <style>…</style> </head> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: indianred; } ❓
/* <head> <style>…</style> </head> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: indianred; }
/* <head> <style>…</style> </head> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: indianred; }
/* <template> <style>…</style> </template> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: skyblue; } ❓
/* <template> <style>…</style> </template> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: skyblue; }
/* <template> <style>…</style> </template> */ .media { display: block; overflow:
hidden; /* Clearfix */ color: skyblue; }
::shadow
/* <head> <style>…</style> </head> */ .speaker::shadow .media { display: block;
overflow: hidden; /* Clearfix */ background-image: url(orion.jpg); background-size: cover; } ❓
/* <head> <style>…</style> </head> */ .speaker::shadow .media { display: block;
overflow: hidden; /* Clearfix */ background-image: url(orion.jpg); background-size: cover; }
Shadow DOM = encapsulation Custom Elements <my-media></my-media>
Shadow DOM = encapsulation Custom Elements
Shadow DOM = encapsulation Custom Elements <my-media> <style> .media {
display: block; overflow: hidden; /* Clearfix */ } .media__image { float: left; margin-right: 10px; } .media__body { overflow: hidden; } </style> <div class="media"> <div class=“media__image"></div> <div class="media__body"></div> </div> </my-media>
Shadow DOM = encapsulation Custom Elements <my-media> ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! </my-media>
Shadow DOM = encapsulation Custom Elements <my-media> ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! </my-media> ! <style> .media { display: table; } .media__image { display: table-cell; vertical-align: top; padding-right: 10px; } </style> <div class="media"> <div class=“media__image"></div> <div class="media__body"></div> </div>
Shadow DOM = encapsulation Custom Elements <my-media> ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! </my-media>
Shadow DOM = encapsulation Custom Elements <my-media> ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! </my-media> ! <style> .media { display: flex; align-items: flex-start; } .media__image { margin-right: 10px; } .media__body { flex: 1; } </style> <div class="media"> <div class=“media__image"></div> <div class="media__body"></div> </div> !
Shadow DOM = encapsulation Custom Elements <my-media></my-media>
HTML5 Rocks http://www.html5rocks.com/
Polymer http://www.polymer-project.org/
X-Tag http://www.x-tags.org/
In future
Polymer designer https://github.com/Polymer/designer
Designer Builder Component Component
Designer Builder Component Component
Component Designer. Be a
Thank you. github.com/hiloki twitter.com/hiloki inkdesign.jp
https://www.flickr.com/photos/premshree/3444104640/ https://www.flickr.com/photos/ltdemartinet/8331549172/ https://www.flickr.com/photos/horiavarlan/4839454263/ https://www.flickr.com/photos/drewmaughan/8209503226/ Photos: