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

まだ間に合う「CSS設計」ことはじめ。CSSの闇に飲み込まれないための考え方。

 まだ間に合う「CSS設計」ことはじめ。CSSの闇に飲み込まれないための考え方。

WP-D Week Day 2 「CSSについてLevel Up!」での発表資料です。

Toro_Unit (Hiroshi Urabe)

April 12, 2016
Tweet

More Decks by Toro_Unit (Hiroshi Urabe)

Other Decks in Technology

Transcript

  1. Toro_Unit ઎෦ ߛ (͏Β΂ ͻΖ͠) Frontend Engineer / Web Designer

    Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit WEB Site: https://torounit.com 2016.4.12 @WP-D Week Day 2 3
  2. Philip Walton ࢯͷݴ͏ྑ͍ CSS ͷ৚݅ͱ͸ɻ • ༧ଌ͠΍͍͢ (PIEͷݪଇ) • ࠶ར༻͠΍͍͢

    (DRYݪଇ) • อक͠΍͍͢ / ֦ு͠΍͍͢ (ΦʔϓϯɾΫϩʔζυͷݪଇ) 2016.4.12 @WP-D Week Day 2 27
  3. .submit-btn { display: inline-block; padding: 10px; color: #FFF; background: #66C;

    } .link-btn { display: inline-block; padding: 10px; color: #333; background: #C90; } 2016.4.12 @WP-D Week Day 2 32
  4. /*Ϙλϯͷߏ଄*/ .btn { display: inline-block; padding: 10px; } /*Ϙλϯͷݟͨ໨*/ .btn-submit

    { color: #FFF; background: #66C; } .btn-link { color: #333; background: #C90; } 2016.4.12 @WP-D Week Day 2 34
  5. ίϯςφͱίϯςϯπͷ෼཭ <aside class="sidebar"> <div> <img class="avatar" /> </div> </aside> .sidebar

    .avatar { width: 200px; border: 5px solid #FFF; box-shadow: 0 2px 3px #000; } 2016.4.12 @WP-D Week Day 2 36
  6. <aside class="sidebar"> <div class="sidebar-widget"> <img class="avatar" /> </div> </aside> .sidebar-widget

    { /** ίϯςφ **/ width: 200px; } .avatar { /** ίϯςϯπ **/ width: 100%; border: 5px solid #FFF; box-shadow: 0 2px 3px #000; } 2016.4.12 @WP-D Week Day 2 38
  7. ίϯςφͱίϯςϯπͷ෼཭ͷϝϦοτ 1. ৔ॴɺίϯςΩετʹґଘ͠ͳ͍ίʔυ͕૿͑Δɻ 2. ࠶ར༻͠΍͍͢ʂ 3. αΠυόʔͷ΢ΟδΣοτʹɺ.widget { width: 200px

    } Έ͍ͨͳ CSS ͱ͔΍Γ͕ͪͰ͚͢ͲɺϑολʔͰ΋࢖͍ͨ ͍...͚Ͳԣ෯͍͕ͯ͠अຐ…ͳΜͯͷ͸ྑ͋͘Δ࿩ɻ 2016.4.12 @WP-D Week Day 2 39
  8. ϖʔδɺσβΠϯΧϯϓ͝ͱʹ CSS Λ࡞Βͳ ͍ɻίϯϙʔωϯτࢦ޲ͳ CSS Λɻ • ͜ΕΛ΍Δͱ͍͍ͩͨɺ৽نϖʔδ௥Ճͷͨͼʹ CSS Λ௥ه

    ͢Δࣄଶ͕ى͜Δɻ • .page-privacy Έ͍ͨͳΫϥεΛbodyΛॻ͔ͳ͍ͱͩΊͳ CSSͱ͔ɺଞͷϖʔδͰ࢖͍͍ͨͱ͖ɺͲ͏͢Δͷʁ • ൚༻ੑͷ͋ΔύʔπΛ૊Έ߹ΘͤͯɺHTML Λ૊ΜͰ͍͚Δ ΋ͷΛ໨ࢦ͢΂͠ɻ 2016.4.12 @WP-D Week Day 2 44
  9. ҰͭͷίϯϙʔωϯτͰ͍Ζ͍Ζ΍Γա͗ͳ͍ɻ • αΠυόʔͷ΢ΟδΣοτʹɺ.widget { width: 200px } Έ͍ͨͳ CSS ͱ͔΍Γ͕ͪͰ͚͢ͲɺϑολʔͰ΋࢖͍ͨ

    ͍...͚Ͳԣ෯͍͕ͯ͠अຐ…ͳΜͯͷ͸ྑ͋͘Δ࿩ɻ • ཁૉͱɺϨΠΞ΢τͷͨΊͷ CSS ͸͔ͬ͠Γ෼ׂɻઈର஋Ͱ αΠζ΍৔ॴΛࢦఆ͍ͯ͠Δ΋ͷ͸ཁ஫ҙɻ • ίϯςφʔͱίϯςϯπͷ෼཭͸͔ͬ͠Γɻ 2016.4.12 @WP-D Week Day 2 47
  10. ηϨΫλʔͷڧ͞͸ՄೳͳݶΓऑ͘ɻ • ID ηϨΫλ͸࢖Θͳ͍ʂηϨΫλʔ͕ແବʹڧ͘ͳͬͯ ! important ஍ࠈΛҾ͖ى͜͢ɻ·ͨɺIDηϨΫλʹ͸ɺϖʔ δ಺ϦϯΫͳͲͷ໾ׂ΋͋ΔͷͰίϯςϯπʹґଘ͕ͪ͠ɻ • .entry-body

    h1 Έ͍ͨͳ͜ͱ΋΍Γ͕ͪͰ͕͢ɺ͜͏͍ͬͨ CSS͕͋ͬͨΓ͢Δͱɺh1ʹΫϥεΛ౰ͯͯ...Έ͍ͨͳͱ͖ ʹ CSS ͕ద༻͞Εͳ͍౳ͷτϥϒϧ͕ɻɻɻ 2016.4.12 @WP-D Week Day 2 48
  11. ਌ཁૉʹґଘͨ͠ηϨΫλʔ͸࢖Θͳ͍ɻ • .comment .title, .entry .title ౳ͷηϨΫλʔ͸Ұݟྑͦ͞͏ͩ ͚Ͳɺ.title ʹ CSS

    ͕͋ͨΒͳ͍ͳΜͯอূ͸ͳ͍͠ɺ.entry ͷதʹ .comment ͕ଘࡏͨ͠৔߹ͱ͔ɻɻɻ.comment- title, .entry-title ౳ɺ਌ཁૉʹґଘ͠ͳ໋໊͍͸େࣄɻ • SMACSSͱ͔ɺBEM౳Λಋೖ͢Δͱָ͔΋ɻ 2016.4.12 @WP-D Week Day 2 49
  12. ػೳɺίϯϙʔωϯτ͝ͱʹϑΝΠϧ෼ׂ͢Δ • Ұຕͷ CSS ϑΝΠϧʹΰϦΰϦॻ͍͍ͯ͘ͱɺͲ͏ͯ͠΋Ұ ͭͷػೳΛ࣮ݱ͢ΔͨΊͷ CSS͕෼ࢄͨ͠Γ͕ͪ͠ɻͳͷ Ͱɺػೳ͝ͱʹ CSS ϑΝΠϧΛ෼ׂ͢΂͠ɻ

    • ҰͭͷίϯϙʔωϯτͰ͍Ζ͍Ζ΍Γա͗ͯͳ͍͔ʁ෼ׂ͢ ΂͖͔ʁ౳ͷࢦ਑ʹ΋ͳΔɻ • ࢖Θͳ͍CSSΛൃݟ͠΍͍͢ɻ 2016.4.12 @WP-D Week Day 2 50
  13. ͓ΘΓɻ Follow Me! Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit WEB

    Site: https://torounit.com 2016.4.12 @WP-D Week Day 2 62