ãã¤ãå¿ãã¦ãæ¯åã©ãã ã£ãã£ãã£ã¦ç¢ºèªããã®ãããã©ãã®ã§ã¾ã¨ãã¦ããã¾ãã
ä»æ§
åç
§ããä»æ§ã¯ CSS3 ã¨ãã¾ããï¼ã¯ã¼ãã³ã°ãã©ãããªã®ã§ããã®å
容ã¯å¤ããå¯è½æ§ãããã¾ãï¼
CSS3 ã®ä»æ§ã¯ä»¥ä¸ããæ¢ãã¦ãã ãã
site:http://www.w3.org/TR/css3 - Google Search
ã«ã¹ã±ã¼ãã£ã³ã°ã¨ã¯
ã«ã¹ã±ã¼ãã£ã³ã°ã«é¢ããè¨èã®æå³ã¯ä»¥ä¸ã«æ¸ãã¦ããã¾ãã
CSS allows several style sheets to influence the rendering of a document, and the process of combining these style sheets is called âcascadingâ.
http://www.w3.org/TR/css3-cascade/#abstract
è¶ æ訳ããã¨
CSS ã§ã¯ä¸ã¤ã® HTML *1ã«å¯¾ãã¦è¤æ°ã®ã¹ã¿ã¤ã«ã·ã¼ãã使ãã¾ããããã¦ãè¤æ°ã®ã¹ã¿ã¤ã«ã·ã¼ããçµåããããã»ã¹ã®ãã¨ããã«ã¹ã±ã¼ãã£ã³ã°ãã¨å¼ã³ã¾ãã
ã¨ãããã¨ã§ãã
ãã£ã¨ç°¡åã«è¨ãã¨
- è¦ç´ ã®è¦ãç®ã£ã¦è¤æ°ã® link è¦ç´ ã¨ã style è¦ç´ ã¨ã style å±æ§ã§ãã£ã±ã宣è¨ããããï¼
- ããããï¼
- 宣è¨ã被ã£ãã¨ãã«ãã©ã®å®£è¨ãé©ç¨ãããã決ããªãã¨ãããªãããï¼
- ããããï¼
- ãã®å®£è¨é¸ææ¹æ³ã®ãã¨ããã«ã¹ã±ã¼ãã£ã³ã°ãã£ã¦ãããï¼
- ã²ãã¼ï¼
ã¨ãããã¨ã§ãã
å®éã®ã«ã¹ã±ã¼ãã£ã³ã°ã解説
ã«ã¹ã±ã¼ãã£ã³ã°ã®æé ã¯ä»¥ä¸ã«æ¸ãã¦ããã¾ãã
The purpose of cascading is to find one winning declaration among the set of declarations that apply for a given element/property combination.
User agents must sort declarations according to the following criteria, in order of importance:
- Weight. In CSS3, the weight of a declaration is based on the origin of the declaration and its marked level of importance. See a separate section below for how to compute the weight. The declaration with the highest weight wins.
- Specificity. The Selectors module [SELECT] describes how to compute the specificity. The declaration with the highest specificity wins.
- Order of appearance. The last declaration wins. Rules in imported style sheets are considered to be before any rules in the style sheet itself. Rules in two imported style sheets are considered to be in the same order as the @import rules themselves.
The sorting process continues until one winning declaration is found.
http://www.w3.org/TR/css3-cascade/#cascading
è¶ æ訳ããã¨
ã«ã¹ã±ã¼ãã£ã³ã°ã¯ãä¸ãããã宣è¨ã®ä¸ãããåã¤å®£è¨ããè¦ã¤ãããã¨ã§ãã
ãã¹ã¦ã®å®£è¨ã以ä¸ã®é ã§ãåæã決ãã¦ããã¾ãã
- ãweightï¼åªå 度ï¼ãã®é«ã宣è¨ãåã¡ã§ãã
- ãweightï¼åªå 度ï¼ããåããã®ã¯ããspecificityï¼è©³ç´°åº¦ï¼ãã®é«ã宣è¨ãåã¡ã§ãã
- ãweightï¼åªå 度ï¼ãã¨ãspecificityï¼è©³ç´°åº¦ï¼ããåããã®ã¯ãæå¾ã«å®£è¨ããã宣è¨ãåã¡ã§ããï¼@import ã®å ´å㯠@import ããã CSS 㯠@import ãã CSS ããå ã«ããã¨ãããã¨ã«ãªãã¾ããããã¦ã @import ããã CSS ãè¤æ°ããå ´åã¯ã @import ãããé ã«å®£è¨ããã¦ããã¨ãã風ã«ãªãã¾ããï¼
ã¨ãããã¨ã§ãã
ãã£ã¨ç°¡åã«ããã¨
- ãã®è¦ç´ ã«ã¯ width ã«é¢ãã宣è¨ããã£ã±ãå®ç¾©ããã¦ãããªãã
- å°ã£ããï¼
- ããããä¸çª weightï¼åªå
度ï¼ãé«ã宣è¨ãé©ç¨ããã
- ã§ããweightï¼åªå 度ï¼ãåã宣è¨ãä¸ã¤ãããã
- ãããããã®ä¸ã§ä¸çª specificityï¼è©³ç´°åº¦ï¼ãé«ã宣è¨ãé©ç¨ããã
- ã§ããweightï¼åªå 度ï¼ã specificityï¼è©³ç´°åº¦ï¼ãåã宣è¨ãäºã¤ããã
- ããããå¾ã«åºã¦ããã»ãã®å®£è¨ãé©ç¨ããã
- ã²ãã¼ï¼
ã¨ãããã¨ã§ãã
ï¼ã¡ãªã¿ã«ãã·ã§ã¼ããã³ããªå®£è¨ãããå ´åã¯ãè¤æ°ã®å®£è¨ããã®ã«ã¼ã«ã»ããã«å®£è¨ããã¦ããã¨æãã°ããã§ããï¼
weightï¼åªå 度ï¼ã¨ã¯ä½ã
ããã©ããªã£ã¦ããã®ã§ãä»æ§ã¸ã®ãªã³ã¯ã¯ããã¾ãã
åªå
度ã¨ã¯ããã®å®£è¨ãå«ã¾ããã¹ã¿ã¤ã«ã·ã¼ãã誰ã«ãã£ã¦ä¸ãããããã¨ããæ
å ±ã¨ !important ã®æç¡ã«ãã£ã¦ãã¾ãã¾ãã
誰ã«ãã£ã¦ä¸ãããããã¯ä»¥ä¸ã®ä¸ã¤ã®ãã¿ã¼ã³ãããã¾ãã
- ã¦ã§ããµã¤ãã«ãã£ã¦ä¸ãããã
- ã¦ã§ããã©ã¦ã¶ã«ãã£ã¦ä¸ãããã
- ã¦ã§ããã©ã¦ã¶ã®ã¦ã¼ã¶ã«ãã£ã¦ä¸ããããï¼ã¦ã¼ã¶ããã©ã¦ã¶ã®è¨å®ãã«ã¹ã¿ãã¤ãºãã¦ããããå ´åï¼
ã§ãåªå 度ãé«ãé ã«ä¸¦ã¹ãã¨
- !important ãå«ã¾ããã¦ã¼ã¶ã«ãã£ã¦ä¸ãããã宣è¨
- !important ãå«ã¾ããã¦ã§ããµã¤ãã«ãã£ã¦ä¸ãããã宣è¨
- !important ãå«ã¾ããªãã¦ã§ããµã¤ãã«ãã£ã¦ä¸ãããã宣è¨
- !important ãå«ã¾ããªãã¦ã¼ã¶ã«ãã£ã¦ä¸ãããã宣è¨
- ã¦ã§ããã©ã¦ã¶ã«ãã£ã¦ä¸ãããã宣è¨
ã¨ãªãã¾ãã
speficityï¼è©³ç´°åº¦ï¼ã¨ã¯ä½ã
詳細度ã®é«ä½ã¯ä»¥ä¸ã®ããã«æ±ºã¾ãã¾ãã*2
- ã¾ããID ã»ã¬ã¯ã¿ï¼#hogehoge, #fugafugaï¼ã®æ°ãå¤ãã«ã¼ã«ã»ããã«å«ã¾ãã宣è¨ã®ã»ãã詳細度ãé«ã
- 次ã«ãID ã»ã¬ã¯ã¿ï¼#hogehoge, #fugafugaï¼ã®æ°ãåããªããã¯ã©ã¹ã»ã¬ã¯ã¿ï¼.hogehoge, .fugafugaï¼ãå±æ§ã»ã¬ã¯ã¿ï¼[title="hoge"], [class$="fuga"]ï¼ãçä¼¼ã¯ã©ã¹ã»ã¬ã¯ã¿ã®åè¨æ°ãå¤ãã«ã¼ã«ã»ããã«å«ã¾ãã宣è¨ã®ã»ãã詳細度ãé«ãã
- 次ã«ãIDã»ã¬ã¯ã¿ã®æ°ã¨ãã¯ã©ã¹ã»ã¬ã¯ã¿ã¨å±æ§ã»ã¬ã¯ã¿ã¨çä¼¼ã¯ã©ã¹ã»ã¬ã¯ã¿ã®åè¨æ°ãåããªããè¦ç´ åã»ã¬ã¯ã¿ï¼div, ul, liï¼ã®æ°ãå¤ãã«ã¼ã«ã»ããã«å«ã¾ãã宣è¨ã®ã»ãã詳細度ãé«ãã
- æå¾ã«ãããã®ãã¹ã¦ã®ã»ã¬ã¯ã¿æ°ãåãã®ãªãã詳細度ã¯åã
- ã¡ãªã¿ã«ãå ¨ç§°ã»ã¬ã¯ã¿ï¼*ï¼ãçä¼¼è¦ç´ ã»ã¬ã¯ã¿ï¼::beforeï¼ã¯è©³ç´°åº¦ã«å½±é¿ãä¸ããªãã
style å±æ§
style å±æ§ã®ãã¨ã¯ã CSS2.1 ã§ã¯ã¡ããã¨è©³ç´°åº¦ã¨ãã¦å®ç¾©ããã¦ããã®ã§ããã CSS3 ã§ã¯ä½æ
ãæ¶ããã¦ãã¾ããä½æ
ï¼
style å±æ§ã«æ¸ããã宣è¨ã¯å®éã®æåã¨ãã¦ã¯ã以ä¸ã®ãããªæåããã¾ãã
- ã¦ã§ããµã¤ãã§å®£è¨ããã宣è¨ã¨ style å±æ§ã§å®£è¨ããã宣è¨ãæ¯ã¹ã㨠style å±æ§ã®å®£è¨ãåã¡ã¾ã
- ã¦ã§ããµã¤ãã§å®£è¨ããã !important 宣è¨ã¨ style å±æ§ã§å®£è¨ããã !important ä»ãã®å®£è¨ãæ¯ã¹ã㨠style å±æ§ã®å®£è¨ãåã¡ã¾ã
ã¾ã¨ã
ããå¿ãã¾ãã
*1:CSS 㯠HTML ã ãã®ä»æ§ã§ã¯ãªãã®ã§ãæ¬æ¥ã¯ãæç« ï¼documentï¼ãã¨ããã¹ãã ããããã§ã¯ç¡é§ã«æ··ä¹±ãããªãããã« HTML ã¨è¨ãåã£ãã
*2:åãåãããããã¨æãæ¸ãæ¹ã§æ¸ãã¦ã¾ããä»æ§ã¨æ¸ãæ¹ãéãã¾ãããåããã¨ã示ãã¦ãã¾ãã