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
140
Other Decks in Design
See All in Design
Первая беседа о Карте реализации историй
ashapiro
0
260
SpectrumTokyoMeetup12_自動貯金アプリ『finbee』での取り組みについて
shihorishimazu
2
380
効果的な管理画面を デザインをするために 避けるべき5つの罠
takanorip
13
5.8k
【Designship 2024|10.13】デザイン組織を進化させるための仕組み化の要諦
payatsusan213
1
480
MLP_Cleanup_Olga
olgastoryboard
0
140
Fleet Gas Station
joshtang
0
130
Slip N Slime - Character Design Ideation
thebogheart
0
290
デザインできるもの、できないもの | Designship 2024 | Yasuhiro Yokota
yasuhiroyokota
2
770
PMとデザイナーはニコイチ! メリットと具体的なアクション10選
mosmos_noki
1
1.1k
私の困りごとと解決案 / My issues and proposed solutions
kubosho
1
270
Карта реализации историй — убийца USM
ashapiro
0
140
Managing Design Systems (Antwerp 2024)
nathanacurtis
1
150
Featured
See All Featured
A better future with KSS
kneath
238
17k
For a Future-Friendly Web
brad_frost
174
9.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Happy Clients
brianwarren
97
6.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
Optimizing for Happiness
mojombo
376
69k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
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: