BEMã¯ããããå Žåã®æ¹æ³è«ãšã¯ã»ã©é ãããšããããŠç¹å®ã®ãããžã§ã¯ãã§ã®BEMã®é©çšã®å¿ èŠæ§ã®åé¡ã¯ãïŒããªããããã奜ããã©ããã«åºã¥ããŠå«ãïŒãã©ã€ããŒãã«èæ ®ãããã¹ãã§ããããšã«ããã«æ³šæãããã§ãã ãŸããææ¡ãããç¹å®ã®ãã¡ã€ã«æ§é ãŸãã¯HTMLçæã䜿çšããªãã£ãããããããã«ã€ããŠã¯èª¬æããŸããïŒåŸã§CSSãã¡ã€ã«ããããã¯ã«å¯Ÿå¿ããåå¥ã®éšåã«åå²ããŸããããä»ã®ãšããããã«éå®ããããšã«ããŸããïŒã ãŸãããã®ã¢ãããŒãå šäœã®é·æãšçæã«ã€ããŠã¯ãã§ã«ããªãã®éãæžãããŠããŸãïŒããšãã°ã ãã ïŒ
éãã
ãããã£ãŠãç§ã®å ŽåãCMSã¯å€§èŠæš¡ã§ã¢ãžã¥ãŒã«åŒã®ãªãŒãã³ãœãŒã¹ãããžã§ã¯ãã§ãããåã¢ãžã¥ãŒã«ã¯ç¬èªã®ããã¯ãšã³ãããŒã¹ãæã¡ãå ±éã®ãã®ã䜿çšããŠç¹å®ã®ã€ã³ã¿ãŒãã§ã€ã¹èŠçŽ ãè¿œå ããŸãã çæ³çã«ã¯ãã¢ãžã¥ãŒã«ã¯ä»ã®éçºè ã«ãã£ãŠéçºãããã¹ãã§ãã ããã¯ãBEMïŒãŸãã¯å¥ã®æ·±å»ãªæ¹æ³è«ïŒã®é©çšãé©åã§ããã ãã§ãªããå¿ èŠãªãããžã§ã¯ãã«éããªããšæããŸãã ããã¯ç¹ã«éèŠã§ããWebéçºè ã®å€ãã¯ãCSSãæ ä¿ã§ããã泚æãæãããæè¡ã培åºçã«ç 究ãããšèããŠãããããæ¢è£œã®ã¬ã€ã¢ãŠããšã¹ã¿ã€ã«ã®éšåãã³ããŒãã奜ããªãã®ã«éäžããŠç®çã®çµæãéæããããšããŠããµããŒããããŠããªãããŒãã«ã«ãªããŸãæãããå質ã®ã¹ã¿ã€ã«ã
æåãæãç°¡åãªæ¹æ³ã¯ããããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã«è§Šããªãããšã§ãããªããªããããã¯éåžžã«å€§ããããã§ãã 代ããã«ãåçŽãªHTMLããã¥ã¡ã³ãïŒ/index.htmlïŒãšã¹ã¿ã€ã«ã·ãŒãïŒ/css/style.cssïŒãäœæãããã¹ãŠã䟿å©ã«ããããã«ãã¹ã¯ãããã«é 眮ãããã®ããã«äžèšã®ç»åããããã€ãã®ãã©ã°ã¡ã³ãã®äœæãéå§ããããšã«ããŸããã¡ã¢åž³++ããã³ãã©ãŠã¶ã ïŒçµæãšããŠãå¿ èŠãªãã¹ãŠã®ã³ã³ããŒãã³ããå«ãããŒãžãååŸããæåãããããããããžã§ã¯ãã«è»¢éãããã£ãã®ã§ããç°¡ç¥åãããçµæã¯ãèšäºã®æåŸã«ãããªã³ã¯ã§ç¢ºèªã§ããŸãã ããã¡ããã芧ãã ãããïŒ
ãã¿ã³
æ§é ã§ã¯ãªããå°ããªãã¿ã³ãããã¯-buttonããå§ããããšã«ããŸããã ãã¿ã³ã«ã¯ãããžãã£ãã¢ã¯ã·ã§ã³ããã¬ãã£ãã¢ã¯ã·ã§ã³ããã¥ãŒãã©ã«ã¢ã¯ã·ã§ã³ã®3çš®é¡ããããŸãã ãããã¯è²ã®ã¿ãç°ãªãããããããã®éããããããããŒã«ä¿®é£Ÿå ã ãã¿ã³-ããžãã£ã ã ãã¿ã³-ãã¬ãã£ã ãããã³ãã¿ã³-ãã¥ãŒãã©ã«ãšããŠèª¬æããŸãã ïŒä¿®é£Ÿåã®ä»£æ¿æ§æãéžæããåäžã®ã¢ã³ããŒã¹ã³ã¢ã®ä»£ããã«2ã€ã®ãã€ãã³ã䜿çšããŸã-ç§ã«ãšã£ãŠã¯ããæ確ã«èŠããŸãïŒã
ãã®çµæãHTMLã§ã¯ãã¿ã³ã¯æ¬¡ã®ããã«èšè¿°ãããŸãã
<button class="button button--positive" type="button">Text</button>
ãŸãããã®ãããªãªãã·ã§ã³ãèš±å¯ããŸãïŒBEMã®æ©èœã®1ã€ã¯ãçæ³çã«ã¯ã䜿çšãããã¿ã°ã®å€èŠ³ã®ç¬ç«æ§ã§ãããã ããã©ã®ã¿ã°ããã¯ã©ã¹ãé©çšã§ããããæ€èšããäžèŠãªã«ãŒã«ã§ã¹ã¿ã€ã«ã·ãŒããæ¡åŒµããŠãã¹ãŠãæäŸããããšã¯ããªããšèããŠããŸãïŒ
<a class="button button--neutral" href="#">Cancel</a>
ãšãŠãèªã¿ããããç解ããããããã«èŠããŸãã CSSãèŠãŠã¿ãŸãããã
.button { border: none; cursor: pointer; font: normal 15px 'PT Sans', sans-serif; line-height: 20px; display: inline-block; padding: 5px 10px; }
ãã¿ã³ã®èª¬æã¯éåžžã«ç°¡åã§ãã ã¯ã©ã¹å ã®ãã¹ãŠã®ã«ãŒã«ã®å€ããªã»ããããããã®æšå¥šäºé ãæºãããŠããŸããïŒç°å¢ã®åœ±é¿ãåããªãããã«ïŒãç§ã«ãšã£ãŠã¯ããã¯ãã§ã«å€ãããŠããããã¯ãåå©çšããå¯èœæ§ãæ¬åœã«ããå Žåã«ã®ã¿å¿ èŠã§ãã¯ãã¬ã€ã¢ãŠãã¹ã¿ã€ã«ãããªãã®ãã®ãšã¯ç°ãªãå¥ã®ãããžã§ã¯ãã§ãïŒããšãã°ãã©ã³ãã£ã³ã°ããŒãžã«iframeãšããŠæ¿å ¥ã§ããªãããçš®ã®ãŠã£ãžã§ãããéçºããŠããå ŽåïŒã ãã¿ã³ãããã¯ã¯ã©ã¹ã¯ãBEMãå¿ èŠãšããããã«ã寞æ³ãå€åŽã®äœçœãæå®ããŸããã
ããã«é²ã¿ãŸãïŒ
.button--positive { background-color: #87b919; color: #fff; } .button--positive:hover { background-color: #a0d71e; color: #fff; } .button--negative { background-color: #ff4100; color: #fff; } .button--negative:hover { background-color: #ff7346; color: #fff; } .button--neutral { background-color: #f0f0f0; } .button--neutral:hover { background-color: #f5f5f5; }
ãããã®ã¯ã©ã¹ã¯ãããŸããŸãªã¿ã€ãã®ãã¿ã³ïŒã¢ã¯ã·ã§ã³ã«å¿ããŠïŒã®ä¿®é£ŸåãšãããŠã¹ã«ãŒãœã«ããããã®äžã«ãããšãã®ç¶æ ãå®çŸ©ããŸãã
ã©ã€ãã®ãã¿ã³ãèŠãŠã¿ãŸãããã
ç§ã®æèŠã§ã¯ãè¯ãã
ãã¿ã³ã°ã«ãŒã
ç§ã®ãããžã§ã¯ãã§ã¯ããã¿ã³ãåç¬ã§äœ¿çšããããšã¯ã»ãšãã©ãããŸãããã»ãšãã©ã®å Žåããã¿ã³ã¯ã°ã«ãŒãã«ã°ã«ãŒãåãããŸãïŒããšãã°ããã©ãŒã ã®ãä¿åããšããã£ã³ã»ã«ãïŒã åã°ã«ãŒãã§ããã¿ã³ã¯æ°Žå¹³æ¹åã«ãçžäºã«ã¡ããã©1ãã¯ã»ã«ã®è·é¢ã«é 眮ããå¿ èŠããããŸãã ãã®è·é¢ãç¶æããã®ãå°é£ã«ãªããªãããã«ïŒ ã€ã³ã©ã€ã³ãŸãã¯ã€ã³ã©ã€ã³ãããã¯èŠçŽ ã®å ŽåãHTMLã®æžåŒèšå®ãã€ãŸãã¿ã°éã®ã¹ããŒã¹ã®ååšã«äŸåããŸãïŒããã¿ã³ã«floatïŒleftã«ãŒã«ãè¿œå ããã®ãæãç°¡åã§ããããã¿ã³ããã¿ã³ã®ã°ã«ãŒãã®èŠçŽ ã§ããå ŽåïŒã€ãŸãããã®ã«ãŒã«ããã¿ã³ãããã¯ã«çŽæ¥è¿œå ããã®ã¯èª€ãã§ãïŒã
ãã®ããããã¿ã³ã®ãã¿ã³ã®ã°ã«ãŒãã®ãããã¯ããã°ã«ãŒãå ã®ãã¿ã³ãè¡šãåäžã®èŠçŽ buttons__buttonã§èª¬æããŸãã 次ã«ããã¿ã³ã°ã«ãŒãã®HTMLã¯æ¬¡ã®ããã«ãªããŸãã
<div class="buttons"> <button class="buttons__button button button--positive" type="button">Send</button> <a class="buttons__button button button--neutral" href="#">Cancel</a> </div>
CSSãæ€èšããŠãã ããã
.buttons { }
ãã¿ã³ãããã¯ã¯ã©ã¹ã¯ç©ºã§ãã
.buttons::after { content: ''; display: block; clear: both; }
ã°ã«ãŒãå ã®ãã¿ã³ã¯ã floatïŒleftãšããã«ãŒã«ãé©çšããããïŒäžââèšã§èª¬æããçç±ïŒããã®æ¹æ³ã§ã©ããããã£ã³ã»ã«ããŸãã ã¡ãªã¿ã«ããããŒãã®åšãã®ãããŒãéãããã®æ¹æ³ãæã奜ãã§ãããå€ããã©ãŠã¶ãŒã§ã¯æ©èœããŸããïŒã»ãšãã©ã®å ŽåããããŒãã«éäžããå¿ èŠã¯ãããŸããïŒã ãããã«ãããããã¯ãã€ã³ãã§ã¯ãããŸããã
.buttons__button { float: left; margin-right: 1px; }
ããã§ã¯ãã°ã«ãŒãã®äžéšã§ãããã¿ã³èŠçŽ ãçŽæ¥èšè¿°ããå³åŽã®1ãã€ã³ãã«ã€ã³ãã³ãããŸãã
.buttons__button:last-child { margin: 0; }
ã°ã«ãŒãã®æåŸã®ãã¿ã³ã¯å³åŽã«ã€ã³ãã³ãããªãã§ãã ãããããã«ã¯ïŒlast-childç䌌ã¯ã©ã¹ã䜿çšããŠãã ãã ã ã°ã«ãŒãå ã®ãã¹ãŠã®ãã¿ã³ãæåŸã§ããå Žåãå³åŽã«ãã®ã€ã³ãã³ããé 眮ãã¹ãã§ã¯ãªããã ã修食åã§ã¯ãªãæ¬äŒŒã¯ã©ã¹ã䜿çšããŸããã ãã®å Žåã®ä¿®é£Ÿåã®äœ¿çšã¯éå°ã ãšæããŸãã
ç§ã®æèŠã§ã¯ãããã¯ããªãã¯ãŒã«ã§ããããšãå€æããŸããã ãããã¯èªäœã¯ããããªãæ¹æ³ã§ãèªèº«ãé 眮ãããå€éšã€ã³ãã³ããèšè¿°ããŸããã ãããããããã¯ãå¥ã®ãããã¯ã«é 眮ãããšãåæã«ãããã¯ã®èŠçŽ ã®ããã«ãªããå¿ èŠã«å¿ããŠãã®å Žæã«å¿ èŠãªãã¹ãŠã®ã«ãŒã«ãè¿œå ã§æå®ã§ããã®ã¯èŠçŽ ã¯ã©ã¹ã§ãã ã¡ãªã¿ã«ãç§ã¯åžžã«æåã«èŠçŽ ã¯ã©ã¹ãé 眮ãã次ã«èŠçŽ 修食åã¯ã©ã¹ãé 眮ãã次ã«ãããã¯ã¯ã©ã¹ãšãã®ä¿®é£Ÿåã®ã¿ãé 眮ããŸãã ããã«ãããHTMLã®èªã¿åããå€§å¹ ã«ç°¡çŽ åãããŸããããã¯ãã¯ã©ã¹ãå€æ°ããå Žåãäœãå«ãŸããŠããããããã«ãããããã§ãã å¥ã®ç¬éïŒå¿µã®ããïŒã CSSã¯ã©ã¹ãé©çšãããé åºã¯ãCSSãã¡ã€ã«ã«è¡šç€ºãããé åºã«ãã£ãŠæ±ºãŸããŸãïŒèŠãç®ã§ã¯ã¯ã©ã¹å±æ§ã«è¡šç€ºãããŸããïŒããããã£ãŠãã¯ã©ã¹ã¯æãåçŽãªãããã¯ã§å®£èšããæåŸã«ãããŒãžæ§é å šäœãæ åœãããããã¯ãé 眮ããå¿ èŠããããŸãã
ãã©ãŠã¶ã§ã®ãã¿ã³ã°ã«ãŒãã®å€èŠ³ã¯æ¬¡ã®ãšããã§ãã
ãã¿ã³ã¯ã»ãŒå®æããŸããã次ã«é²ã¿ãŸãã
ããã¹ããã£ãŒã«ããšããã¹ããšãªã¢
次ã«ãä»ã®ã³ã³ãããŒã«ãæ±ãããšã«ããŸããã åæ§ã«ãããã¹ããã£ãŒã«ãã®ããã¹ãããã¯ã¹ãšããã¹ããšãªã¢ã®ããã¹ããšãªã¢ã®ãããã¯ã«ã€ããŠèª¬æããŸããïŒãããã¯ã¯ã»ãŒåäžãªã®ã§ãããã¹ããšãªã¢ã¯èæ ®ããŸãã-äŸã®ãœãŒã¹ã³ãŒããèŠãããšãã§ããŸãïŒã 以äžã¯ãHTMLããã¹ãããã¯ã¹ãããã¯ã§ãã ããã«ã text-box-required修食åãè¿œå ãããŸããããã¯ããã£ãŒã«ããå¿ é ã§ããããšãæå³ããŸãïŒãã£ãŒã«ãã®å³åŽã«èµ€ãããŒãè¿œå ãããŸãïŒã
<input class="text-box text-box--required" type="text" />
é¢é£ããCSSã¯ã©ã¹ã¯æ¬¡ã®ããã«ãªããŸãã
.text-box { background-color: #f0f0f0; border: none; font: normal 15px 'PT Sans', sans-serif; line-height: 20px; outline: none; padding: 5px 10px; resize: none; } .text-box:hover { background-color: #f5f5f5; } .text-box:focus { background-color: #f5f5f5; } .text-box--required { border-right: 5px solid #ff4100; }
ããã§ç¹å¥ãªããšã¯äœããããŸããããæåŸã®ããã¹ãããã¯ã¹ä¿®é£Ÿå-requiredãç¹°ãè¿ããŸã ã ããã¹ãé åã«ã1ã€ãããŸããã text-area-requiredãšåŒã°ããŸã ã
ããã¹ãããã¯ã¹ã¯æ¬¡ã®ããã«ãªããŸãã
ãã©ãŒã ãã£ãŒã«ã
ãã¿ã³ã®å Žåãšåæ§ã«ãããã¹ããã£ãŒã«ããšé åããããžã§ã¯ãã§åç¬ã§é©çšãããããšã¯ã»ãšãã©ãããŸããã ã»ãšãã©ã®å Žåããã©ãŒã ãã£ãŒã«ãã®åœ¢åŒã§ãã©ãŒã ã®äžéšãšããŠäœ¿çšãããŸãïŒããšãã°ãããããŒãšããã¹ããã£ãŒã«ãã®çµã¿åããïŒã ã€ãŸãããã©ãŒã ã¯åã ã®ã³ã³ãããŒã«ããã§ã¯ãªããå°ããªå®æããããŒã¹ããçµã¿ç«ãŠãããŸãã ããã§ã ãã£ãŒã«ããããã¯ãè¿œå ãã field__label ã field__text-box ãããã³field__text-areaèŠçŽ ã䜿çšããŠããã©ãŒã ãã£ãŒã«ãå ã®ããããŒãšããã¹ããã£ãŒã«ãããã³ãšãªã¢ã®åäœã説æããããšã«ããŸããã ãã®çµæãããã¹ãé åã®ããHTMLãã©ãŒã ãã£ãŒã«ãã¯æ¬¡ã®ããã«ãªããŸãã
<div class="field"> <label class="field__label label">Body</label> <textarea class="field__text-area text-area"></textarea> </div>
ãã¹ãŠãã·ã³ãã«ã§ãã ããäžåºŠãã¯ã©ã¹ã®é åºã«æ³šæããŠãã ããã æåã«ãããšãã°ã field__labelãç¶ãããã®åŸã«label-ã©ãã«ã¿ã°ãäž»ã«ãã®ãã£ãŒã«ããããã¯ã®field__labelèŠçŽ ã§ããããã®åŸã ãç¬ç«ããã©ãã«ãããã¯ã§ããããã§ãã ãã®åäžæ§ã¯éåžžã«åœ¹ç«ã¡ãŸãã CSSãæ€èšããŠãã ããã
.field { }
ãã®ã¯ã©ã¹ã¯ç©ºã§ãã ãã©ãŒã ãã£ãŒã«ãããã©ãŒã ã«çŽæ¥è¡šç€ºããå Žåããããã®éã«åçŽã€ã³ãã³ããå¿ èŠã§ããã以äžã®ãã©ãŒã ãããã¯ã®å¯Ÿå¿ããform__fieldèŠçŽ ã§ããã説æããŸãã
.field__label { display: block; margin-bottom: 1px; }
ãã£ãŒã«ããããã¯å ã®ããããŒã¯æ°ããè¡ã«è¡šç€ºãããäžãã1ãã¯ã»ã«åã€ã³ãã³ããããŸãã
.field__text-box { width: 430px; } .field__text-area { width: 430px; height: 190px; }
ãããã®2ã€ã®ã¯ã©ã¹ã䜿çšããŠããã©ãŒã ãã£ãŒã«ãã®èŠçŽ ã§ããããã¹ããã£ãŒã«ããšãšãªã¢ã®ãµã€ãºãæå®ããŸãã ãã®ãã¹ãŠã®çµæã¯æ¬¡ã®ãšããã§ãã
ãŸããç§ã®ãã©ãŒã ãã£ãŒã«ãã®äžéšã¯ããŒã«ã©ã€ãºãããŠããŸãïŒå€èšèªïŒã ããã¹ããã£ãŒã«ããŸãã¯ãšãªã¢ãå±ããèšèªã瀺ãããã«ãè¿œå ã®èŠèŠããŒã«ãŒãå¿ èŠã§ãã HTMLã§ã¯ãããŒã«ã©ã€ãºãããããã¹ããã£ãŒã«ãã®ã»ãããæã€ãã©ãŒã ãã£ãŒã«ãã¯æ¬¡ã®ããã«ãªããŸãã
<div class="field"> <label class="field__label label">Subject</label> <div class="field__culture"> <div class="field__culture-flag">en</div> </div> <input class="field__text-box field__text-box--multilingual text-box text-box--required" type="text" /> <div class="field__multilingual-separator"></div> <div class="field__culture"> <div class="field__culture-flag">ru</div> </div> <input class="field__text-box field__text-box--multilingual text-box text-box--required" type="text" /> </div>
ããã¹ããã£ãŒã«ãã®ã¯ã©ã¹ã®ã»ããã«æ³šæããŠãã ããã4ã€ã®ã¯ã©ã¹ããããŸãã ããäžåºŠèª¿ã¹ãŠã¿ãŸãããã field__text-boxã¯ã©ã¹ã¯ããã©ãŒã ãã£ãŒã«ãå ã®ããã¹ããã£ãŒã«ãã®ãµã€ãºãå®çŸ©ããŸããfield__text-box-å€èšèªã¯å³åŽã«å°ããªã€ã³ãã³ããè¿œå ããå ¥åäžã®æåãããã¹ãããŒã«ãŒã®äžã«è¡šç€ºãããèšèªããŒã«ãŒã®äžã«åãŸããªãããã«ããŸãã ããã¹ãããã¯ã¹ã¯ã©ã¹ã¯ãããã¹ããã£ãŒã«ãã®åºæ¬çãªãã©ã¡ãŒã¿ãŒãå®çŸ©ãã ããã¹ãããã¯ã¹-ãã£ãŒã«ãã®å³åŽã«èµ€ãããŒãè¿œå ããŸãã
æ°ããCSSã¯ã©ã¹ïŒ
.field__culture { position: relative; left: 450px; width: 0; z-index: 10; } .field__culture-flag { background-color: #323232; color: #fff; cursor: default; font-size: 8px; line-height: 16px; text-align: center; text-transform: uppercase; position: absolute; left: -23px; top: 7px; width: 16px; height: 16px; } .field__multilingual-separator { height: 1px; }
ããã§èª¬æããããšã¯äœããããŸããã æåã®2ã€ã®ã¯ã©ã¹ã¯ãããã¹ããã£ãŒã«ããŸãã¯ããã¹ãé åã®äžã«èšèªããŒã«ãŒã衚瀺ããããã«å¿ èŠã§ããæåŸã®ã¯ã©ã¹ã¯ãç°ãªãèšèªã®ã³ã³ãããŒã«éã«é«ã1ãã¯ã»ã«ã®ã€ã³ãã³ããè¿œå ããããã«å¿ èŠã§ãã
ãã©ãŒã
次ã«ããã©ãŒã ãããã¯formã«ã€ããŠèããŸãã ãã©ãŒã ã¯ããã§ã«èª¬æãããã©ãŒã ãã£ãŒã«ããšãã¿ã³ã°ã«ãŒãã§æ§æãããŠããŸãããèŠçŽ ã¯ã©ã¹form__fieldããã³form__buttonsã䜿çšããŠãåçŽã€ã³ãã³ããè¿œå ããŸãã ããã¯ã ãã©ãŒã ãããã¯ã®ç°¡æHTMLã®ããã§ãã
<form class="form"> <div class="form__field field"> <label class="field__label label">Body</label> <textarea class="field__text-area text-area"></textarea> </div> <div class="form__buttons buttons"> <button class="buttons__button button button--positive" type="button">Send</button> <a class="buttons__button button button--neutral" href="#">Cancel</a> </div> </form>
ãããŠãããã«åœŒã®CSSããããŸãïŒ
.form { } .form__field { margin-top: 10px; } .form__buttons { margin-top: 20px; }
ã芧ã®ãšããããã¹ãŠãæããã§ãã å¿ èŠã«å¿ããŠãããšãã°ããŠã§ããµã€ãã®ã³ã³ãããŒã«ããã«ã«ãã¿ã³ã®ã°ã«ãŒããæ¿å ¥ã§ããŸããããã©ãŒã ã«ã€ããŠè©±ããŠããå Žåã¯ããã¿ã³ã®ã°ã«ãŒãã«è¿œå ã®ã¯ã©ã¹form__buttonsãæäŸããäžããå¿ èŠãªã€ã³ãã³ããååŸããŸãã
ãã©ãŠã¶ã§ã¯ããã©ãŒã å šäœã¯æ¬¡ã®ããã«ãªããŸãã
ããŒãã«
ããã§ã¯ãããå°ãè€éãªèŠçŽ ãã€ãŸãããŒãã«ãèŠãŠã¿ãŸãããã ããŒãã«ã¯ããŒãã«ã§æ§æããå¿ èŠãããããšã¯èª°ããç¥ã£ãŠãããšæããŸãïŒããã¯ã»ãã³ãã£ãã¯ã«åœãŠã¯ãŸãããã©ãŠã¶ãé©åã«ãµããŒãããŠããããïŒãããããã¢ãããã£ãã¬ã€ã¢ãŠãã®å Žåã¯ã 衚瀺ïŒããŒãã« ãã®å Žåãã¢ãã€ã«ããã€ã¹ã§ã¯ãæ°Žå¹³ããŒãã«ãç°¡åã«åçŽãªã¹ãã«å€æãã衚瀺ãããããŒã¿ãããããæ¹æ³ã§æäœããŸãïŒäœããé衚瀺ã«ããããçµã¿åããããããããšãã§ããŸãïŒã ãããããç§ã®ãããžã§ã¯ãã§ã®ããŒãã«ã®å®è£ ã«ã¯tableã䜿çšããããšã«ããŸããããäžéšã¯å®éšãšããŠããããè¡ãåã«divã䜿çšããŠæ§æããŸããã BEMãã¿ã°ããç¬ç«ããŠããããšã®å©ç¹ã¯ã divã¿ã°ãtable ã tr ãããã³tdã«çœ®ãæããããšã§ããCSSãã¡ã€ã«ãå€æŽããå¿ èŠã¯ãªããããŒãã«ã¯åãããã«èŠããŸããã æ¯èŒã®ããã«äž¡æ¹ã®ãªãã·ã§ã³ãæå®ããŸããã
HTMLã®æšæºããŒãã«ã¯æ¬¡ã®ããã«ãªããŸãã
<table class="table"> <tr class="table__row"> <th class="table__cell table__cell--header">Cell</th> <th class="table__cell table__cell--header">Cell</th> <th class="table__cell table__cell--header">Cell</th> </tr> <tr class="table__row"> <td class="table__cell">Cell</td> <td class="table__cell">Cell</td> <td class="table__cell">Cell</td> </tr> </table>
ã芧ã®ãšãããåã¿ã°ã«ã¯ã¯ã©ã¹ãäžããããŠããŸãã ç°åžžã«èŠãããããããŸãããã table ã tr ã tdãdivã«ç°¡åã«å€æŽã§ããèŠèŠçã«éãã«æ°ä»ããªãããã«ããããšãã§ããŸã ã
CSSããŒãã«ïŒ
.table { border-collapse: collapse; display: table; width: 100%; } .table__row { display: table-row; } .table__cell { font-weight: normal; text-align: left; vertical-align: top; display: table-cell; padding: 5px 10px; } .table__row:hover .table__cell { background: #ffff96; } .table__cell--header { background: #f0f0f0; } .table__row:hover .table__cell--header { background: #f0f0f0; }
ã芧ã®ãšããããããã¯èªäœãšãã®èŠçŽ ã«ã€ããŠãã«ãŒã«displayïŒtable ã displayïŒtable-rowããã³displayïŒtable-cellãèšå®ãããŠããŸãã ããã«ããããããã¯ã¯ã¿ã°ããæ¯èŒçç¬ç«ããŸãã å®éãç¹°ãè¿ããŸãããããŒãã«ãåžžã«æ£ç¢ºã«æšæºã®ããŒãã«ã¿ã°ã§æ§æãããããšã確å®ãªå Žåããããã®ã«ãŒã«ã«æå³ããããšã¯æããŸããã
æåŸã«ãã©ã€ãã§çµæãèŠãŠã¿ãŸãããã
ã¡ãã¥ãŒ
æçµæ®µéã«é²ã¿ãŸãã ã¡ãã¥ãŒã¯ã¡ãã¥ãŒãããã¯ã§è¡šãããŸãã åã¡ãã¥ãŒã«ã¯ãã¡ãã¥ãŒèŠçŽ ã®è€æ°ã®ã°ã«ãŒãïŒ menu__groupèŠçŽ ïŒãå«ããããšãã§ããåã°ã«ãŒãã«ã¯ãã¡ãã¥ãŒèŠçŽ ã®ã°ã«ãŒãã®1ã€ã®ã¿ã€ãã«ïŒ menu__group-titleèŠçŽ ïŒãšè€æ°ã®ã¡ãã¥ãŒèŠçŽ ïŒ menu__itemèŠçŽ ïŒãå«ããããšãã§ããŸãã é¢é£ããHTMLã¯æ¬¡ã®ãšããã§ãã
<div class="menu"> <div class="menu__group"> <div class="menu__group-title sub-title"> Group title 1 </div> <a class="menu__item" href="#">Menu item 1</a> <a class="menu__item" href="#">Menu item 2</a> <a class="menu__item" href="#">Menu item 3</a> </div> </div>
menu__groupèŠçŽ ãšmenu__itemèŠçŽ ãå¥ã ã®ãããã¯ã«ããããšãèããŸãããããã®ãããªè§£æ±ºçãæ¯æããåŒæ°ã¯èŠã€ãããŸããã§ãããä»ã®å Žæã§ã¯äœ¿çšãããŸãããããã¯ã¯ã©ã¹æ°ã®å¢å ã«ã€ãªããã ãã§ãã
ãã¹ãŠãæããã§ããããã«èŠããŸãããæ確ã«ããããã«ãCSSãæäŸããŸãã
.menu { } .menu__group { } .menu__group-title{ } .menu__item { display: block; padding: 5px 0; }
ãã®å Žåãäžéšã®ã¯ã©ã¹ã¯ç©ºã§ãã ã芧ã®ããã«ãããšãã°ãã¡ãã¥ãŒé ç®ã®ã°ã«ãŒãã®ããããŒã®å€èŠ³ã¯ãäžè¬çãªãµãã¿ã€ãã«ãããã¯ã«ãã£ãŠæ±ºå®ãããŸãïŒãœãŒã¹ã§åæ¢ããªãã§ãã ãã-èŠãŠãã ããïŒã 空ã®ã¯ã©ã¹ã¯å¿ èŠãããŸããïŒããããããããåé€ããå¿ èŠããããŸãïŒã äŸã®æ確åã®ããã«ãããããæ®ãããšã«ããŸããã
ã¡ãã¥ãŒèªäœã¯æ¬¡ã®ããã«ãªããŸãã
äžè¬çãªæ§é
æåŸã«ãããŒãžã®å šäœçãªæ§é ãæ€èšããŸãã ãããããã®åã«ããã1ç¹è§ŠããããšæããŸãã äºå®ãäž»ã«BEMã®èšäºã§ã¯ãCSSãã¡ã€ã«å ã®ãããã¯ã«é¢é£ããªãã«ãŒã«ãæããªãããšãæšå¥šãããŠããŸãã ã€ãŸããããã¥ã¡ã³ãå šäœã«é©çšãããäžè¬çãªã«ãŒã«ïŒããšãã°ãã¯ã©ã¹ã§ã¯ãªãã¿ã°ã«ããã»ã¬ã¯ã¿ãŒïŒã ãã®å Žåãåãããã¯ãŸãã¯èŠçŽ ã§è€è£œããå¿ èŠã®ããã«ãŒã«ã®æ°ãå¢ããããããã®æ¹æ³ã䜿çšããªãããšã«ããŸããã ç§ã®å Žåããããè¡ãç¹å¥ãªçç±ã¯ãããŸããã èããŠã¿ããšãç§ã®ãããžã§ã¯ãã®ãã¹ãŠã®ãããã¯ã¯åäžã®ã³ã³ããã¹ãã®ãã¬ãŒã ã¯ãŒã¯å ã§èšè¿°ãããŠãããäžå€ã§ããããšãã°ãããã¹ãã«å ±éã®ã¹ã¿ã€ã«ãèšå®ãããã¹ãŠã®ãããã¯ã§ãããæ§ç¯ããã®ã¯ããŸã£ããåãã§ãã¹ã¿ã€ã«ã
ããã«ãåèŠåºããããã¹ãã®æ®µèœãåãªã³ã¯ã«ã¯ã©ã¹ãå²ãåœãŠãããšã¯äžå¿ èŠãªããã§ãã ãã®å Žåãããšãã°WYSIWYGãšãã£ã¿ãŒã䜿çšãããšãã¯ããããã®ã¯ã©ã¹ãæåã§è¿œå ããå¿ èŠããããŸãïŒãŸãã¯ä¿åæã«èªåçã«è¿œå ããŸãïŒã ãããã«ãããããã¯éåžžã«äžäŸ¿ã§ãã
äžè¬çãªæ§é ã«æ»ããŸãã 2ã€ã®äž»èŠãªèŠçŽ ã§ããmaster-detail__masterããã³master-detail__detailãæã€1ã€ã®ãã¹ã¿ãŒè©³çŽ°ãããã¯ã«è¡šç€ºããããšã«ããŸããããããã¯ãããããããŒãžã®å·Šæãéšåãšå³æããéšåãæ åœããŸãã
master-detail__masterã«ã 2ã€ã®ã¡ãã¥ãŒãè¿œå ããŸããã 1ã€ã®ã¡ãã¥ãŒã«ã¯ãããã€ãã®CSSã«ãŒã«ã§è£è¶³ããå¿ èŠããªããã ã master-detail__masterèŠçŽ ã®è¿œå ã¯ã©ã¹ã¯å«ãŸããŸããã 2çªç®ã®ã¡ãã¥ãŒãmaster-detail__secondary-menuèŠçŽ ã§ã master-detail__masterèŠçŽ ã®äžéšã«é 眮ããŸã ã ããã«ããã®2çªç®ã®ã¡ãã¥ãŒã®èŠçŽ ã¯master-detail__secondary-menu-itemèŠçŽ ãšãæ··åããããŠãããç°è²ã«ãªããŸãã
ãã®ãããã¯ã®HTML / CSSã¯åŒçšããŸãããããã¯æ±ãã«ãããããããŒãžã³ã³ãã³ãã®æ®ãã®ã³ã³ããã¹ãã§èæ ®ããå¿ èŠãããããã§ãã ãããã£ãŠããã¹ãã±ãŒã¹ã®ãœãŒã¹ã³ãŒããåç §ããããšããå§ãããŸãããªã³ã¯ã¯ä»¥äžã«ãããŸãã
ãŸããããŒãžã«ã¯ãã1ã€ã®ãããã¯-ã¿ãããããŸããã ãããã¯ã¯éåžžã«åçŽãªã®ã§ãããããèšè¿°ããããšã¯ãã¯ãæå³ããªããšå€æããŸããã
æåŸã«ãæåã®åçãšåãçµæãåŸãããŸãã
çµè«
ãªããããæžãããšã«ããã®ã§ããïŒ BEMã«å¯ŸåŠãå§ãããšããæ確ãªçããèŠã€ããããšãã§ããªãã£ãå€ãã®è³ªåããããŸããã ããã¯äžçš®ã®åå®æããã¢ã€ãã¢ã§ããã åæ§ç¯ããŠHTMLã¬ã€ã¢ãŠãããã»ã¹ãå確èªããããã«ã¹ã±ãŒãã®äœ¿çšãæåŠãããããããšã¯èå³æ·±ãããšã§ããã ãã®çµæãã©ãã«ãããŠèªåèªèº«ã®è§£æ±ºçãèŠã€ããŸããããã®çµéšãå ±æããŠã誰ãã«ãã®ãæ £ããŠåæ§ç¯ãããããã»ã¹ãç°¡çŽ åããå¥ã®èŠç¹ã瀺ããããšæããŸããã
æ¹æ³è«å šäœãæ°ã«å ¥ããŸããã ç§ã®æèŠã§ã¯ãæãéèŠãªããšã¯ãæ§é åãåœåã¹ã¿ã€ã«ãªã©ã«é¢ããŠãéçºè ãããªãã¿ã€ããªãã¬ãŒã ã¯ãŒã¯ã«æŒã蟌ãããšã§ãã ãã®çµæãã»ãšãã©ã®å Žåããæ¹æ³ããšãã質åã«å¯Ÿããçãã¯1ã€ã ãã§ããããã¯éåžžã«ã¯ãŒã«ã§ãïŒç¹ã«å€§èŠæš¡ãªãããžã§ã¯ããããŒã ãããžã§ã¯ãïŒã
å°èŠæš¡ã§ã·ã³ãã«ãªãããžã§ã¯ãã§BEMã䜿çšããŸããïŒ ãŸã ããããŸããã ã¯ã©ã¹ã®æ°ãå¢ããããã«äžå¿ èŠãªå°é£ããŸã£ããçµéšãããäžå¿ èŠãªãã¹ãã¬ã¹ãã«æ°ä»ããŸããã§ããããæ¹æ³è«ã«åŸãããšã¯ãåŸæ¥ã®ãã¢ãããŒããããå°ãå€ãã®åªåãå¿ èŠãšããŸãã ãããããããã¯çµéšãšåšçšãã®æ¬ åŠã«ãããã®ã§ãã
é¢çœãã£ããšæããŸãã ããã§ã©ã€ããšã¿ãããèŠãããšãã§ããŸããã ããã«ãããžã§ã¯ãã®å®éã®ãã¢ããããŸããããã¯ãäŸãšããŠæããç°¡ç¥åããã管çããã«ã®äžéšã§ãã ããã§ãå®éã®ã¹ã±ãŒã«ã§ãããã©ã®ããã«èŠããããèŠãããšãã§ããŸãããŸããå¿ èŠã«å¿ããŠã以åã®ç¶æ ãšæ¯èŒã§ããŸãã