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

迷わない!学べば分かるCSS設計

Yohei Munesada
February 05, 2015

 迷わない!学べば分かるCSS設計

Web業界なんでも勉強会(第2回)のセッション内容です。

Yohei Munesada

February 05, 2015
Tweet

More Decks by Yohei Munesada

Other Decks in Technology

Transcript

  1. ಉ͡Α͏ͳ͜ͱͰ೰ΜͰ͍Δਓ͕͍Δ Throwing every new style you create onto the end

    of a single file would make finding things more difficult and would be very confusing for anybody else working on the project. 
 Of course, you likely have some organization in place already. ৽͘͠ελΠϧΛఆٛ͢Δͨͼʹɺ ϑΝΠϧͷ࠷ޙʹ௥هͯ͠ߦͬͨͷͰ͸ɺ ΋͏ͦΕ͸ݟ͚ͭΔͷ͸ࠔ೉ͩ͠ɺଞͷਓ΋ࠞཚͤͯ͞͠·͏ɻ ΋͔ͨ͠͠Βطʹಉ͡Α͏ͳελΠϧ͕ଘࡏ͢Δ͔΋͠Εͳ͍ɻ https://smacss.com/book/categorizing
  2. Object Oriented CSS a CSS “object” is a repeating visual

    pattern, that can be abstracted into an independent snippet of HTML, CSS, and possibly JavaScript. That object can then be reused throughout a site. ܁Γฦ͠දݱ͞ΕΔύλʔϯΛ$44ΦϒδΣΫτͱͯ͠ଊ͑ɺ ͦΕ͸)5.- $44 +BWB4DSJQU͔Βߏ੒͞ΕΔಠཱͨ͠ϞδϡʔϧͰ͋Δɻ ಠཱ͍ͯ͠ΔͨΊϞδϡʔϧ͸αΠτ಺Λ௨ͯ͠࠶ར༻͢Δ͜ͱ͕Ͱ͖Δɻ https://github.com/stubbornella/oocss/wiki
  3. Scalable and Modular At the very core of SMACSS is

    categorization. By categorizing CSS rules, we begin to see patterns and can define better practices around each of these patterns. 4."$44ͷ࠷΋ίΞͱͳΔߟ͑ํ͸෼ྨͰ͢ɻ $44ϧʔϧΛ෼ྨ͢Δ͜ͱͰύλʔϯΛݟ͚ͭΔ͜ͱ͕Ͱ͖ɺ ͦΕΒύλʔϯΛ࣮ݱ͢ΔͨΊͷΑΓྑ͍ํ๏Λཱ֬͢Δ͜ͱ͕Ͱ͖·͢ɻ Architecture for CSS https://smacss.com/book/categorizing
  4. Block, Element, Modifier We used BEM principles to create a

    set of front-end development techniques and tools. A block is an independent entity, An element is a part of a block, and A modifier is a property of a block or an element that alters its look or behavior. #&.ͷݪཧ͸ϑϩϯτΤϯυ։ൃͷςΫχοΫ΍πʔϧΛ࡞Γग़͢ɻ #MPDL͸ಠཱͨ͠ϖʔδͷߏ੒ཁૉͰ͋Γɺ&MFNFOU͸#MPDLͷཁૉͰ͋Γɺ .PEJpFS͸#MPDL΍&MFNFOUͷঢ়ଶΛมߋͤ͞ΔཁૉͰ͋Δɻ https://bem.info/method/definitions/
  5. html,body,div,p { margin:0; padding:0; } body { background: white; font-family:

    "Bell MT"; font-size:16px; color:#333; } a { color:#336633; } table { … } 㾎 )5.-ཁૉ΁ͷ૷০Λߦ͏ 㾎 $44ϦηοτΛఆٛ͢Δ 㾎 JNQPSUBOU͸࢖Θͳ͍ 㾎 άϩʔόϧʹఆٛ͢Δ αΠτશମͰڞ௨ͷελΠϧ - Base
  6. .l-header { background: #091f29; color: #fff; text-align: right; font-size: 90%;

    } .l-primary { background: #3399cc; } 㾎 άϩʔόϧʹఆٛ͢Δ 㾎 *%૷০΋0,͕ͩʜɺ/PU(PPE 㾎 M<ϨΠΞ΢τ໊>ͷωʔϛϯάϧʔϧ αΠτͷࠎ૊ΈΛఆٛ͢Δ - Layout
  7. .intro {…} .intro-image { float: left; margin-right: 20px; } 㾎

    άϩʔόϧʹఆٛ͢Δ͜ͱͰ
 ਌ཁૉ͔Βಠཱͤ͞Δ 㾎 Ϟδϡʔϧ໊ΛΫϥε໊ʹ͢Δ ͻͱ·ͱ·ΓͷػೳΛ࣋ͭ - Module 㾎 Ϟδϡʔϧͷߏ੒ཁૉ͸ɺ
 <Ϟδϡʔϧ໊><ཁૉ໊>ͷ
 ωʔϛϯάϧʔϧ͕ྑ͍͔΋ #&.ΑΓ
  8. HTMLཁૉ΁ͷम০Λආ͚Δ - Module <div class="fld"> <span>Folder Name</span> </div> .fld span

    { padding-left: 20px; background: url(folder-icon.png); } HTML CSS
  9. ΋͠ӡ༻Ͱมߋ͕͋ͬͨ৔߹ <div class="fld"> <span>Folder Name</span> <span>(32 items)</span> </div> .fld >

    span {…} .fld > span:last-child { padding-left: 0; background: none; } HTML CSS ໘౗ͳΧεέʔυ͕ ൃੜ͢Δ
  10. <div class=“l-nav”> <div class="pod"> <input type=“text” class=“pod-input”> </div> </div> HTML

    φϏήʔγϣϯ಺Ͱ͸inputͷԣ෯Λݻఆ͍ͨ͠ʂ .l-nav .pod .pod-input { width: 180px; } CSS ਌ΫϥεͰΧεέʔυ͠ͳ͍ MOBWͰ͔͠ ࢖͑ͳ͍ ελΠϧͷ ࠶ར༻͕Ͱ͖ͳ͍
  11. HTML ղܾࡦɿΧεέʔυ༻ͷΫϥεΛ࡞੒͢Δ .pod.pod-constrained .pod-input { width: 180px; } CSS MOBWҎ֎Ͱ΋

    ࢖͑Δ ελΠϧͷ ࠶ར༻͕Ͱ͖Δ <div class=“l-nav”> <div class=“pod pod-constrained"> <input type=“text” class=“pod-input”> </div> </div>
  12. <div class="message is-error"> There are some errors… </div> 㾎 JT<ঢ়ଶ໊>ͷωʔϛϯάϧʔϧ

    㾎 ඞཁʹԠͯ͡JNQPSUBOU΋࢖͏ 㾎 άϩʔόϧͳ$44ͱͯ͠ఆٛ͢Δ ঢ়ଶͷมԽΛఆٛ͢Δ - State .message { background: green; color: white; } .is-error { background: red; }
  13. .tab { background: purple; color: white; } ղܾࡦɿϞδϡʔϧ໊ΛΫϥε໊ʹؚΊΔ CSS 㾎

    ಛఆϞδϡʔϧʹର͢Δ
 4UBUF༻ͷΫϥε໊ͷωʔϛϯά͸ɺ
 JT<Ϟδϡʔϧ໊><ঢ়ଶ໊>ͱ͢Δ .is-tab-active { background: white; color: black; }
  14. // in module-name.css .mod { border: 1px solid; } //

    in dark-theme.css .mod { border-color: blue; } 㾎 ผ$44ϑΝΠϧʹఆٛͯ͠ɺ
 ඞཁʹԠͯ͡ಡΈࠐΈΧεέʔυ͢Δ ςʔϚΛมߋ͢Δ - Theme 㾎 CPEZʹಛఆͷΫϥεΛ෇༩͢Δ͜ͱͰ
 ΧεέʔυΛߦ͏