モダンなCSS設計パターンを考える
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

モダンなCSS設計パターンを考える

  • 6,477 views
Uploaded on

HTML5 Conference 2013 "モダンなCSS設計パターンを考える" の一部を改変したQCon Tokyo 2014 版スライドです。

HTML5 Conference 2013 "モダンなCSS設計パターンを考える" の一部を改変したQCon Tokyo 2014 版スライドです。

More in: Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
6,477
On Slideshare
5,483
From Embeds
994
Number of Embeds
7

Actions

Shares
Downloads
45
Comments
1
Likes
62

Embeds 994

https://ocean.cybozu-dev.com 794
https://twitter.com 173
https://ocean.s.cybozu-dev.com 15
http://s.deeeki.com 9
http://bootstrap.oktopic.com 1
https://tweetdeck.twitter.com 1
https://www.chatwork.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. QCon Tokyo 2014 Conference Modern CSS Architecture Hiroki Tani モダンなCSS設計パターンを考える
  • 2. Hiroki Tani Front-end Engineer CyberAgent, Inc.
  • 3. ?Why Architecture
  • 4. #news h2 { border-bottom: 1px solid black; padding: 1em 0.5em; font-size: 18px; font-weight: bold; }
  • 5. #news h2 { border-bottom: 1px solid black; padding: 1em 0.5em; font-size: 18px; font-weight: bold; } ! #faq .title { border-bottom: 1px solid black; padding: 1em 0.5em; font-size: 18px; font-weight: bold; }
  • 6. #news h2 { border-bottom: 1px solid black; padding: 1em 0.5em; font-size: 18px; font-weight: bold; } ! #faq .title { border-bottom: 1px solid black; padding: 1em 0.5em; font-size: 18px; font-weight: bold; } ! #service .feature .title { border: 1px solid black; padding: 0.5em; font-size: 16px; }
  • 7. .column_2 #inbox .list { ... } .column_3 #inbox .list { ... } .column_3 #inbox .list .name { ... } .column_3 #inbox .list .name p { ... } .column_3 #inbox .list .name.reply { ... } .column_3 #inbox .list .name.reply a { ... } body#top .column_3 #inbox .list.left { ... }
  • 8. !important
  • 9. Goals of Better CSS Architecture -Predictable -Reusable -Maintainable -Scalable http://article.enja.io/articles/css-architecture.html 予測しやすい 再利用しやすい 保守しやすい 拡張しやすい
  • 10. Modular CSS
  • 11. OOCSS Nicole Sullivan https://github.com/stubbornella/oocss/wiki
  • 12. OOCSS -Separate structure and skin -Separate container and content 構造と見た目の分離 コンテナとコンテンツの分離
  • 13. Media object
  • 14. <div class="media"> <div class="media-image"> <img src="/img/seminar/15/tani.jpg"> </div> <div class="media-body"> <p>...</p> <ul> <li><a>...</a></li> </ul> <p>...</p> </div> </div>
  • 15. <div class="media"> <div class="media-image"> <img src="/img/seminar/15/tani.jpg"> </div> <div class="media-body"> <p>...</p> <ul> <li><a>...</a></li> </ul> <p>...</p> </div> </div>
  • 16. <div class="media"> <div class="media-image"> <img src="/img/seminar/15/tani.jpg"> </div> <div class="media-body"> <p>...</p> <ul> <li><a>...</a></li> </ul> <p>...</p> </div> </div>
  • 17. .media { /* Clearfix */ } .media-image { float: left; margin-right: 10px; } .media-image > img { display: block; } .media-body { overflow: hidden; }
  • 18. <div class="media skin-a"> <div class="media-image"> <img src="/img/seminar/15/tani.jpg"> </div> <div class="media-body"> <p>...</p> <ul> <li><a>...</a></li> </ul> <p>...</p> </div> </div>
  • 19. <div class="media skin-b"> <div class="media-image"> <img src="/img/seminar/15/tani.jpg"> </div> <div class="media-body"> <p>...</p> <ul> <li><a>...</a></li> </ul> <p>...</p> </div> </div>
  • 20. ?How to build modules
  • 21. It depends.
  • 22. Rule of Three ‘Refactoring’ http://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)
  • 23. 3, 6
  • 24. 3, 6, 9, 12, 15 ...
  • 25. 3, 6, 12, 24, 48 ...
  • 26. 3, 6, 9
  • 27. 3, 6, 9, 12, 15 ...
  • 28. .fontSize10 { font-size: 10px } .colorRed { color: red }
  • 29. <p class="fontSize18 colorRed"> 入力内容に誤りがあります。 </p>
  • 30. <p class="box radius10 fontSize18 colorRed"> 入力内容に誤りがあります。 </p>
  • 31. .fontSize18 { font-size: 18px }
  • 32. .fontSize18 { font-size: 18px } ! @media only screen and (max-width : 320px) { .fontSize18 { font-size: 14px } } ⚠
  • 33. .colorRed { color: red }
  • 34. .colorRed { color: orange; } ⚠
  • 35. .colorRed { color: orange; /* あとで直す */ } ⚠
  • 36.
  • 37. ?How to maintain modules
  • 38. SMACSS Jonathan Snook http://smacss.com/ja 日本語、あります
  • 39. SMACSS -Categorization -Naming Convention -Decoupling CSS from HTML カテゴライズ 命名規則 HTMLとCSSの分離
  • 40. SMACSS Categories -Base -Layout -Module -State -Theme
  • 41. /* # Base */ body, form { margin: 0; padding: 0; } a { color: #039; } a:hover { color: #03F; }
  • 42. /* # Layout */ #header { width: 960px; margin: auto; } .l-article { border: solid #CCC; border-width: 1px 0 0; } .l-grid { margin: 0; padding: 0; list-style-type: none; } .l-grid > li { display: inline-block; margin: 0 0 10px 10px; }
  • 43. /* # State */ .is-hidden { display: none; } .is-error { font-weight: bold; color: red; } .is-tab-active { border-bottom-color: transparent; }
  • 44. /* # Theme */ /* ## Spring Theme CSS */ .theme-header { background-image: url("/theme/spring/ header.png"); } .theme-border { 1px solid pink; }
  • 45. Message-box http://cdpn.io/hKBkm
  • 46. <div class="msg"> <p>...</p> </div> .msg { display: block; border: 1px solid #cccccc; border-radius: 8px; padding: 1em; background-color: #efefef; color: #333333; }
  • 47. <div class="msg msg-error"> <p>...</p> </div> .msg { ... } .msg-error { border: 1px solid #c0392b; background-color: #fe9282; }
  • 48. <div class="msg msg-success"> <p>...</p> </div> .msg { ... } .msg-success { border: 1px solid #27ae60; background-color: #99f3c9; }
  • 49. <div class="msg msg-error"> <h2>...</h2> <p>...</p> </div>
  • 50. <div class="msg msg-error"> <h2>...</h2> <p>...</p> </div> .msg h2 { font-size: inherit; font-weight: bold; } ! .msg p { margin-top: 0.6em; }
  • 51. .msg h2 { font-size: inherit; font-weight: bold; } ! .msg ul, .msg p { margin-top: 0.6em; } ⚠
  • 52. <div class="msg msg-error"> <h2 class="msg-title"> ... </h2> <ul class="msg-body"> <li>...</li> <li>...</li> </ul> </div>
  • 53. .msg-title { font-size: inherit; font-weight: bold; } ! .msg-body { margin-top: 0.6em; }
  • 54. <div class="msg msg-error"> <p class="msg-title"> ... </p> <ul class="msg-body"> <li>...</li> <li>...</li> </ul> </div>
  • 55. <div class="msg msg-error"> <h2 class="msg-title"> <i class="msg-title-icon ico ico-label ico-alert"></i> ... </h2> <ul class="msg-body"> <li>...</li> <li>...</li> </ul> </div>
  • 56. .msg-title-icon { vertical-align: -0.3em; } ! .ico { display: inline-block; } ! .ico-alert { background-image: url(...); width: 24px; height: 24px; } ! .ico-label { margin-right: 0.3em; }
  • 57. %ico { display: inline-block; } ! %ico-alert { background-image: url(...); width: 24px; height: 24px; } ! %ico-label { margin-right: 0.3em; } ! .msg-error-icon { vertical-align: -0.3em; @extend %ico; @extend %ico-alert; @extend %ico-label; }
  • 58. ! .msg-error { border: 1px solid #c0392b; background-color: #fe9282; }
  • 59. .msg-title { font-size: inherit; font-weight: bold; } .msg-body { margin-top: 0.6em; }
  • 60. .msg { ... } .msg-error { border: 1px solid #c0392b; background-color: #fe9282; } .msg-title { font-size: inherit; font-weight: bold; }
  • 61. BEM Yandex http://bem.info/
  • 62. BEM stands for ... -Block -Element -Modifier
  • 63. Block
  • 64. Element
  • 65. Modifier
  • 66. .block { ... } .block__element { ... } .block_modifier { ... } .block__element_modifier { ... }
  • 67. .nav { ... } .nav__item { ... } .nav_segmented { ... } .nav__item_segmented { ... }
  • 68. .nav { ... } .nav__item { ... } .nav--segmented { ... } .nav__item--segmented { ... } http://enja.studiomohawk.com/2012/03/20/about-html-semantics-and-front-end-architecture/
  • 69. .msg { ... } .msg--error { border: 1px solid #c0392b; background-color: #fe9282; }
  • 70. .msg__title { font-size: inherit; font-weight: bold; } .msg__body { margin-top: 0.6em; } .msg__title-icon { vertical-align: -0.3em; }
  • 71. MCSS -Base -Project -cosmetic http://operatino.github.io/MCSS/en/
  • 72. FLOCSS -Foundation -Layout -Object https://github.com/hiloki/flocss -Component -Project -Utility
  • 73. Front-end Styleguide
  • 74. Starbucks Style Guide http://www.starbucks.com/static/reference/styleguide/
  • 75. MailChimp Pattern Library http://ux.mailchimp.com/patterns/
  • 76. Twitter Bootstrap http://getbootstrap.com
  • 77. A Pattern Apart http://patterns.alistapart.com/
  • 78. http://alistapart.com/blog/post/getting-started-with-pattern-libraries Code Example view
  • 79. http://alistapart.com/blog/post/getting-started-with-pattern-libraries Patchwork view
  • 80. Front-end Styleguide
  • 81. Front-end Styleguide Living
  • 82. KSS http://warpspire.com/kss/styleguides/
  • 83. Kalei http://kaleistyleguide.com/
  • 84. StyleDocco http://jacobrask.github.io/styledocco/
  • 85. // // # 見出し // // 説明文を書きます。マークダウン形式です。 // // ``` // <button type="button" class="btn btn-default"> // ``` で囲んだ部分にデモのHTMLを記述します。 // </button> // ``` ! .btn { display: inline-block; ... &:hover, &:focus { color: @btn-default-color; text-decoration: none; } }
  • 86. $ styledocco -n "ProjectName" css/ $ styledocco -n "ProjectName" -o "mydocs" $ styledocco -n "ProjectName" --preprocessor "lessc" less/
  • 87. http://d.pr/v/46BF
  • 88. ⚏🎬 👤👤 ⚏🎬 👤 Building Pages Systems
  • 89. Styleguide Driven Development http://www.stubbornella.org/content/2014/04/09/style-guide-driven-development/
  • 90. Developer vs Designer ?
  • 91. ⚏🎬 👤👤
  • 92. Developer with Designer
  • 93. Best Practice
  • 94. Best Practices
  • 95. どんなに多くの人が貢献したとしても どのコードも一人で書いたようにする https://github.com/necolas/idiomatic-css - Idiomatic CSS All code in any code-base should look like a single person typed it, even when many people are contributing to it. “ ”
  • 96. 壊れない完璧な設計を求めるのではなく 壊れたときに勇気をもって修復できる設計を “ ” - Anonymous
  • 97. Thanks. - twitter.com/hiloki - inkdesign.jp - slideshare.net/hiloki
  • 98. Photo credit - http://www.flickr.com/photos/bpotstra/3490333174/sizes/l/ - http://www.flickr.com/photos/bettybroadbent/3704523854/sizes/o/ - http://www.flickr.com/photos/drewmaughan/8209503226/sizes/l/ - http://www.flickr.com/photos/biodork/6849406792/ - http://www.flickr.com/photos/43266097@N03/9444574320/sizes/l/ - http://www.flickr.com/photos/90585146@N08/8234225693/sizes/l/ - http://www.flickr.com/photos/lwr/6778863776/sizes/l/ - http://www.flickr.com/photos/jezpage/4696962046/ - http://www.flickr.com/photos/april-mo/8485249298/sizes/l/ - http://www.flickr.com/photos/4st4roth/2366615948/ - http://www.flickr.com/photos/sharman/4570412801/sizes/l/ - http://www.flickr.com/photos/kaptainkobold/3771497484/ - http://www.flickr.com/photos/laurie_pink/2549598674/sizes/l/ - http://www.flickr.com/photos/dansdata/3266946102/ - http://www.flickr.com/photos/ochre_jelly/6839227477/sizes/l/ - http://www.flickr.com/photos/in-duce/2232109985/sizes/o/ - http://www.flickr.com/photos/pgoyette/5911926699/sizes/z/ - http://www.flickr.com/photos/conradoplg/10091603396/sizes/l/ - http://www.flickr.com/photos/kaptainkobold/4441509147/sizes/l/