Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Components

Hiroki Tani
June 21, 2014

CSS Components

2014-06-21 Frontrend in Nagoya w/ HTML5 NAGOYA

Hiroki Tani

June 21, 2014
Tweet

More Decks by Hiroki Tani

Other Decks in Design

Transcript

  1. CSS

  2. 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
  3. <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>
  4. .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; } …
  5. <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>
  6. .book { overflow: hidden; /* Clearfix */ padding: 20px; background-color:

    #9DBCB8; color: #FFF; } .book .cover { float: left; margin-right: 20px; } .book .inner { overflow: hidden; } .book .title { ... } ...
  7. <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>
  8. .event > a { display: block; } .event .thumbnail {

    float: left; margin-right: 15px; } .event .inner { overflow: hidden; } …
  9. <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>
  10. /* Media */ .media { overflow: hidden; /* Clearfix */

    } .media__image { float: left; margin-right: 15px; } .media__body { overflow: hidden; }
  11. .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; } …
  12. .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; } …
  13. .book { overflow: hidden; /* Clearfix */ padding: 20px; background-color:

    #9DBCB8; color: #FFF; } .book .cover { float: left; margin-right: 20px; } .book .inner { overflow: hidden; } .book .title { ... } ...
  14. .event > a { display: block; } .event .thumbnail {

    float: left; margin-right: 15px; } .event .inner { overflow: hidden; } …
  15. <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>
  16. <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>
  17. #pickup .book__name { color: #111; font-size: 2em; } ! .book__name

    { margin-bottom: 10px; line-height: 1.3; font-weight: bold; font-size: 1.2em; }
  18. #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; }
  19. #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; }
  20. <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>
  21. 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) ); };
  22. 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
  23. <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>
  24. <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>
  25. <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>
  26. /* <head> <style>…</style> </head> */ .media { display: block; overflow:

    hidden; /* Clearfix */ color: indianred; } ❓
  27. /* <head> <style>…</style> </head> */ .speaker::shadow .media { display: block;

    overflow: hidden; /* Clearfix */ background-image: url(orion.jpg); background-size: cover; } ❓
  28. /* <head> <style>…</style> </head> */ .speaker::shadow .media { display: block;

    overflow: hidden; /* Clearfix */ background-image: url(orion.jpg); background-size: cover; }
  29. 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>
  30. Shadow DOM = encapsulation Custom Elements <my-media> ! ! !

    ! ! ! ! ! ! ! ! ! ! ! ! ! </my-media>
  31. 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>
  32. Shadow DOM = encapsulation Custom Elements <my-media> ! ! !

    ! ! ! ! ! ! ! ! ! ! ! ! ! </my-media>
  33. 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> !