OOCSS(Object-Oriented CSS)ã®èãæ¹
CSSã§ãµã¤ããä½ãã¨ãããã¼ã¸ãidã§åºåãããã®ä¸ã®classã«å¯¾ãã¦ã¹ã¿ã¤ã«ãæå®ããã¨ããããæ¹ãä¸è¬çãããªãããªã¨æãã¾ãã
#page-foo .box {margin:10px } #page-baa .box {margin:20px }
ãããããããã®ãã¼ã¸ã®ãã®é¨åããã®ãã¼ã¸ã«æã£ã¦ãããâ¦ã¨ãªãã¨CSSãã¡ã¤ã«ãã¨æã£ã¦ããªããã°ãªããªãã移転å ã®classåã¨ãããã£ã³ã°ãã¦ãã¾ããªã©åå©ç¨ãé£ããã¨ããåé¢ãããã¾ãã
ä»åä»äºã§ãµã¤ããæ§ç¯ããã«ããããåå©ç¨å¯è½ãªã¢ã¸ã¥ã¼ã«ã§æ§æããã°ã³ã¼ãã£ã³ã°ã«ãããå·¥æ°ã¯æ¸ãã®ã§ã¯ã¨èãã¦ããã®ã§ï¼ç¹ã«IEã®ãã°é¢é£â¦æ¤è¨¼æ¸ã¿ã®ã¢ã¸ã¥ã¼ã«ã§æ§æããã°ç¢ºå®ï¼ï¼åå©ç¨æ§ã¨ããã©ã¼ãã³ã¹ãéè¦ãããã¬ã¼ã ã¯ã¼ã¯OOCSSã«ã¤ãã¦èª¿ã¹ã¦ã¿ã¾ããã
OOCSSã®åºæ¬çãªèãæ¹
ç®çå¥ã«classãè¤æ°æå®ããã
idã«ä¾åãããã±ã¼ã·ã§ã³ã§è¦ãç®ãåºåãã®ã§ã¯ãªãã使ããæ¹ã«å¿ãã¦classåãã¤ãã¾ããã½ã¼ã¹ã§èª¬æãã¦ããããã«ããã®ã§ä¾ãããã¾ããããã§ã¯ããã¤ãã³ã°ãã¼ãã«ã«ç½®ããããªãã³ã®ã¤ãã大ããªç®±ãããã¼ã¯ã¢ããããã¨ãã¾ãã
ãã±ã¼ã·ã§ã³å¥ã«åããå ´å
<div id="#ãã¤ãã³ã°ãã¼ãã«"> <div class="ãªãã³ã®ã¤ãã大ããªç®±">â¦</div> </div>
ã¨ãã¼ã¯ã¢ãããã¦ãã¾ããã
ãããOOCSSã§ã¯
<div> <div class="ç®± 大ãã ãªãã³">â¦</div> </div>
ã¨è¨è¿°ãã¦ãã¾ãããã¤ãã³ã°ãã¼ãã«ãã¡ç¡è¦ã§ãããããããã®ç®±ã¯ã¡ãã¶å°ã®ä¸ã«ããã®ã¾ã¾ç½®ããããã«ãªã£ãããã§ãw
ã¾ãããã·ã¼ã«ã®è²¼ã£ã¦ããå°ããªç®±ãã表ç¾ãããã¨ãã
<div> <div class="ç®± å°ãã ã·ã¼ã«">â¦</div> </div>
ã¨ãªããã.ç®±ãã¯åå©ç¨ã§ããããã§ãã
ç¡é§ã«ç®±ã®ã¹ã¿ã¤ã«ãããã¤ãè¨è¿°ããå¿
è¦ããªããªãã¾ãããåãããã«ã大ãããå°ãããããç®±ãã ãã§ãªããè¢ããªããã«ãåå©ç¨ã§ããããã§ããè¯ãèãã¦ã¿ãã°ç®±ã®ä¾ã®ããã«ãç®±ã¨ããæ©è½ã¯ãã¼ãã«ã«ãã£ã¦å·¦å³ããããããããªãã§ãããããã©ãã«ãã£ã¦ãç®±ã¯ç®±ã¨ãã¦ä½¿ããï¼ããç®±ã¨ãã¦ã®å¤§åæï¼ã£ã¦ãã¨ã§ããã
æ§é ã¨ã¹ãã³ãåé¢ãã
å
ç¨ã®ä¾ã§è¨ãã¨ãç®±ãã大ããããæ§é ãããªãã³ããã¹ãã³ã«ãªãã¾ããå®éã«OOCSSã®ãã³ãã¬ã¼ããè¦ã¦ã¿ãã¨ã以ä¸ã®å³ã®ããã«ãªã£ã¦ãã¾ãã
ã.lineãããã¼ã¸ã«æ¨ªããã£ã¦ãã大æ ãã.unitãã.size1of3ããã«ã©ã ã¨ãã®å¹ ãã.modããã¢ã¸ã¥ã¼ã«ã¨ãã£ãæ§é ã表ããã¦ãã¾ããã.grabãã.excerptãã.sommersãã¯ã¢ã¸ã¥ã¼ã«ã«å½ã¦ãããã¹ãã³ã§ããæ§é ã«ã¯ marginãfloatãªã©ã®é£æ¥è¦ç´ ã«å½±é¿ãä¸ããããããã£ããã¹ãã³ã«ã¯backgroundãborderãªã©ã®è£ 飾系ããããã£ãã·ã³ãã«ã«æå®ããã¦ãã¾ãã
ããã©ã¼ãã³ã¹ãè¯ã
ãã±ã¼ã·ã§ã³ã§ãã¡ããã¡ãæ¸ããªãåãCSSè¨è¿°ãã·ã³ãã«ã«ãªãããã©ã¼ãã³ã¹ãè¯ããªãã¾ããåå«ã»ã¬ã¯ã¿ã¯ããã©ã¼ãã³ã¹ã«è¯ãããã¾ãããï¼ãããªã«å¤ãããã¨ã®èª¬ããã§ããâ¦ï¼
ãbeforeã #page-hoge .hogebox . hogeclass {ã»ã»ã»} ãafterã .hogeclass {ã»ã»ã»}
å®éã«ä½¿ã£ã¦ã¿ã¦
CSSã§ããã¾ã§æ§é ã«ã¤ãã¦çå£ã«èãããã¨ã¯ãæ¥ããããªããããã¾ããã§ããï½
ãã¾ã¾ã§ã¯ããç¨åº¦å ´å½ããçã«ãããã¯ãã®ãããã®marginã§ããã ãã¼ãã§æ¸ãã§ããé¨åãããããã¯.lineã ããmarginã¯ããã¤ã§â¦ãã¨ãã£ã¡ã決ãã¦ç½®ããªãã¨ãã¹ã¦ã«å½±é¿ãã¦ãã¾ãã®ã§ããå¾ã
ã®åå©ç¨ã®ãã¨ã¾ã§èãã¦ã³ã¼ãã£ã³ã°ããªãã¨ãããªãã®ã§ãåæå·¥æ°ã¯ãããã¾ãããåå©ç¨æ§ã¯ç³ãåãªãã§ãã
èªåã¯ãã¹ãã³ã®ã©ã¤ãã©ãªãã¼ã¸ãã¾ãã³ã¼ãã£ã³ã°ããããããã³ããã§ããºã«ã®ããã«ãã¼ã¸ã«ã¯ãããã§ããæ¹æ³ãã¨ã£ã¦ãã¾ããæ¤è¨¼æ¸ã¿ã®æ§é ã®ä¸ã«ã¹ãã³ããã¶ãã¦ããã ããªã®ã§ãã©ã¦ã¶éã®è¡¨ç¤ºå´©ããããã¾ããã
ã¶ã£ã¡ãããã³ãã¬ã¼ãã®htmlã¯ããã©ã¼ãã³ã¹ãæ±ç¨æ§ãæãããããããã¡ãã£ã¨è¤éãªä½ãã«ãªã£ã¦ãã¾ããå®éã«ä½¿ç¨ããã«ã¯å³ããé¨åãçµæ§ããã¨æãã¾ããï¼è§ä¸¸ã®ããã«ç©ºã®bã¿ã°ã大éã«ãã£ããâ¦ï¼ãªã®ã§ããã³ãã¬ã¼ããç´æ¥ã«ã¹ã¿ãã¤ãºããããã¯èãæ¹ã身ã«ã¤ãã¦è¦ä»¶ã«åããèªåã§æ§ç¯ãã¦ãã£ãæ¹ãããããããã¾ããã
ã©ãã ãåªãããã¬ã¼ã ã¯ã¼ã¯ãããã¾ã§éå
·ã§ãããªããèªåã®æã«ãªãã¾ããªãã¨ãããã®ã¯ä½ããªãã¨æãã¾ããã