ãã§ã«ããããåºåã£ã¦ãã¾ããããããã£ãæ å ±ã¯1ã¤ã ãããã°è¯ãããã§ã¯ãªãããããã®æ å ±ãã¾ã¨ããããç²¾æ»ãã¦ãã£ã¦ãããã«ããè¯ããã®ã«ãªã£ã¦ããã®ãWebã®è¯ãã¨ããã ã¨æãã¾ããæ¥åãè¡ãä¸ã§ã¡ã¢ãã¦ãããã®ã貯ã¾ã£ã¦ããã®ã§ããã®çç±ã¨ãã調ã¹ã¦ã¿ãã®ã§ã¾ã¨ãã¾ããã¾ãåç½®ãã¯ãããããã«ãã¦æ¬é¡ã
CSSãã·ã³ãã«ã«å¹çè¯ãæ¸ãã¨ãããã¨ã¯ããããã¯ã¼ã¯è»¢ééã®ä½ä¸ããã¼ã¹é度ã®åä¸ãããã¦HTMLã¨ã®ãããã³ã°å¹çåã«ç¹ããã¾ããããã¦ããã¯å³ã¡ããã¼ã¸ã®ããã©ã¼ãã³ã¹ãåä¸ããããã¨ã«ç¹ããã¾ãã
ã¾ãããå¹ççãªã¹ã¿ã¤ã«æå®ããããã¨èããªããè¨ãã¨è©ã«åãå ¥ã£ã¦ãã¾ãã¾ããããéå¹çãªã¹ã¿ã¤ã«æå®ãããªããã¨ããè¦ç¹ã§èãã¦ããã°ãèªãã¨è»½éã§å¹ççãªCSSãè¨è¿°ãããã¨ãã§ããã¨æãã¾ãã
ãéå¹çãªã¹ã¿ã¤ã«æå®ãã®åã«ã¾ããã¹ã¿ã¤ã«ããã¦ãããä»çµã¿ãç¥ã£ã¦ããã¨ãç解ããããã§ãã
CSSã§ã¯ãã¿ã¼ã³ãããï¼Pattern matchingï¼ã®è¦åãç¨ãã¦ï¼ææ¸ããªã¼ã®åè¦ç´ ã«é©ç¨ãããã¹ã¿ã¤ã«è¦åã決å®ãã¾ããã»ã¬ã¯ã¿ã¨å¼ã°ãããããã®ãã¿ã¼ã³ã¯åç´ãªè¦ç´ ååã®ã¿ã®ãã®ããï¼è¤éãªåå¾é¢ä¿ï¼ãã¨ãã°åä¾ãåå«ï¼å å¼ãªã©ï¼ãç §åã§ãããã®ã¾ã§å¤å²ã«äºãã¾ãããã¿ã¼ã³å ã«ç¤ºãããå ¨æ¡ä»¶ãããè¦ç´ ã¨ä¸è´ããã¨ãï¼ãã®ã»ã¬ã¯ã¿ã¨è¦ç´ ã¯ãããï¼matchï¼ãã¦ããã¨è¬ãã¾ãã
Webãã©ã¦ã¶ã¯ãèªã¿è¾¼ãã HTMLããã¼ã¹ãã¦ãDOMããªã¼ãä½æãã¾ãããã®å¾ãããªã¼ã辿ããªããããããã®è¦ç´ ã«ã¤ãã¦ãåã¹ã¿ã¤ã«ãåè´ãããã©ãããæ¤è¨¼ãã¦ããã¾ãããã®ä½æ¥ã¯åºæ¬çã«ã¯ãå
¨ã¦ã®è¦ç´ ã«å¯¾ãã¦ãå
¨ã¦ã®ã¹ã¿ã¤ã«ã«ã¼ã«ãæ¤è¨¼ããã¨ããä½æ¥ã«ãªãã¾ããã¤ã¾ããHTMLå
ã®å
¨è¦ç´ æ° * CSSå
ã®ã«ã¼ã«æ°
åããããã³ã°ãè¡ãããã¨ãããã¨ã«ãªãã¾ãã
<head>
<style type="text/css">
body { ... }
div { ... }
.sample h1 { ... }
</style>
</head>
<body>
<div> ... </div>
<div class="sample">
<h1> ... </h1>
<div> ... </div>
</div>
</body>
ä¸è¨ã®ãããªææ¸ããã£ãã¨ãã¾ãããã®ææ¸å
ã«ã¯è¦ç´ ã5ã¤(body
, h1
, div * 3
)ãã¹ã¿ã¤ã«ã3ã¤ããã¾ãã5ã¤ã®åè¦ç´ ã«å¯¾ãã¦ã3ã¤ã®ã«ã¼ã«ãããããããã©ãããæ¤è¨¼ããã®ã§ããããã³ã°åæ°ã¯5 * 3ã¨ãªããè¨15åã®ãããã³ã°ãä¸è¨ã®ææ¸ã§è¡ãããè¨ç®ã«ãªãã¾ãã
ã¹ã¿ã¤ã«ã·ã¹ãã ã¯ããã¼ã»ã¬ã¯ã¿(key selector(ã«ã¼ã«ã®ä¸çªå³ã«æ¸ãããã»ã¬ã¯ã¿))ã«ãããCSSã«ã¼ã«ã大ãã4ã¤ã®åºåã«åãã¦æ±ãã¾ãã
#sample { ... }
.sample p,
address { ... }
div.sample form input[checked="checked"] { ... }
ä¸è¨ã®å ´åããã¼ã»ã¬ã¯ã¿ã¯#sample
, p
, address
, input[checked="checked"]
ã¨ãªãã¾ãã
ãã¼ã»ã¬ã¯ã¿ãIDæå®ãã¦ãããã®ã以ä¸ã¯ãã®ä¾ã
div#sample { ... }
#sample { ... }
table tr.sample td#myCell:active { ... }
ãã¼ã»ã¬ã¯ã¿ãã¯ã©ã¹æå®ãã¦ãããã®ã以ä¸ã¯ãã®ä¾ã
div.sample { ... }
.menu { ... }
.section .date:active { ... }
ãã¼ã»ã¬ã¯ã¿ãã¿ã°æå®ãã¦ãããã®ã以ä¸ã¯ãã®ä¾ã
body { ... }
.section p { ... }
input[type="checkbox"] { ... }
ä¸è¨3ã¤ã®ã«ã¼ã«ã«å½ã¦ã¯ã¾ããªãå ¨ã¦ã®ãã®ã以ä¸ã¯ãã®ä¾ã
* { ... }
.footer * { ... }
:lang(ja) { ... }
[hidden="true"] { ... }
ã¹ã¿ã¤ã«ã·ã¹ãã ã¯åã ã®ã«ã¼ã«ã«ããã¦ã対象è¦ç´ ã«ããããããã©ãããããã¼ã»ã¬ã¯ã¿ããé ã ã«(å·¦ã«åãã£ã¦)確èªãã¦ããã¾ããã¾ããã¹ã¿ã¤ã«ã·ã¹ãã ã¯ããªã¼ã対象è¦ç´ ã«é©åãç¶ãã¦ããéããã«ã¼ã«ããããããããã¹ãããã§çµäºããã¾ã§ç¢ºèªãç¶ãã¾ãã
<body>
<div class="section">
<div class="menu">
<ul>
<li id="aboutMe"> ... </li>
</ul>
</div>
.
.
.
</div>
</body>
ä¸è¨ã®HTMLã®li
ã«ã以ä¸ã®ã«ã¼ã«ã§ã¹ã¿ã¤ã«ããããããã¦ã¿ã¾ãã
.section .menu ul li { ... }
ãã¼ã»ã¬ã¯ã¿ã§ããli
ãã¿ã°ãªã®ã§ããã®ã«ã¼ã«ã¯ãã¿ã°ã«ã¼ã«ãã«åé¡ããã¾ãã
li
ã«ããããããã©ããã確èªããæ¤è¨¼ãéå§ãã(5è¡ç®ã«li
ãçºè¦)ul
ã§ãããã©ããã確èªãã(4è¡ç®ã«ul
ãçºè¦)div
ããããã©ããã確èªãã(2è¡ç®ã«div class="section"
ãçºè¦)次ã«ã以ä¸ã®ã«ã¼ã«ã§ã¹ã¿ã¤ã«ããããããã¦ã¿ã¾ãã
#aboutMe { ... }
ããã¯å½ç¶ããIDã«ã¼ã«ãã«åé¡ããã¾ãã
以ä¸ã§ããããã¯æ¥µç«¯ãªä¾ã§ãããã¹ã¿ã¤ã«æå®ã®å¹çã®è¯ãæªããæ³åã§ããã¨æãã¾ãã
ããã§ã¯ã以ä¸ã®ããã¿ã¼ã³ãããã³ã°ããè¸ã¾ãã¦ããå¹ççãªCSSãæ¸ãããã®æéãåã³ãå¹ççã»éå¹çãªã¹ã¿ã¤ã«æå®ãã®ä¾ãæãã¦ããããã¨æãã¾ãã
ãã¼ã»ã¬ã¯ã¿ã«ãã£ã¦ãã«ã¼ã«ã¯4種é¡ã«åãããã¾ãããä¸è¬ã«ã¼ã«ãã¯ãIDã§ãã¯ã©ã¹ã§ãã¿ã°ã§ããªãã«ã¼ã«ã§ãããã®ã«ã¼ã«ã¯å ¨ã¦ã®è¦ç´ ã常ã«ç«ã¡æ¢ã¾ã£ã¦ç¢ºèªãã¦ãã¾ããããæãéå¹çãªã«ã¼ã«ã§ããGeneric Resetãªã©ã®ããã«ã便å©ãªä½¿ãæ¹ãããã®ã§ããããªãã¹ã使ããªãããã«ãã¾ãããã
IDã¯ãã¼ã¸å ã§å®å ¨ã«ä¸æãªãã®ã§ãããããã ãã§å¯¾è±¡è¦ç´ ãç¹å®ã§ããã®ã§ãããã«ã¿ã°ãã¯ã©ã¹åãæå®ãããã¨ã¯å ¨ãã®ç¡é§ã§ããå ´åã«ãã£ã¦ã¯ãã¹ã¯ãªãããªã©ã§ã¯ã©ã¹æå®ãåãæ¿ããããã«ãã£ã¦åããå¤ãããå ´åãªã©ãããããããã¾ãããããããã®å ´åã§ããã¯ã©ã¹åãã¦ãã¼ã¯ã«ãããã¨ã§ãç¡é§ãªè¨è¿°ãé¿ãããã¨ãã§ãã¾ãã
à div#personal_info { ... }
à .footer#copyright { ... }
â #personal_info { ... }
â #copyright { ... }
.section * { ... }
blockquote p { ... }
* .menu ul li a { ... }
ä¸è¨ã®ãããªã»ã¬ã¯ã¿ãåå«ã»ã¬ã¯ã¿(descendant selector)ã¨å¼ã³ã¾ããåå«ã»ã¬ã¯ã¿ã¯é¢ä¿ã辿ãã»ã¬ã¯ã¿ã¨ãã¦ã¯ãæããããã³ã°ã³ã¹ããæããã»ã¬ã¯ã¿ã§ããè¦ç´ ããããããéãDOMããªã¼ã辿ããã¨ãç¹°ãè¿ãã®ã§ããã¼ã»ã¬ã¯ã¿ãã¦ããã¼ãµã«ã»ã¬ã¯ã¿ãã¿ã°æå®ã§ãã£ãå ´åãããããã¨ã«ãªãã¾ãã
è¦ç´ ã®é¢ä¿æ§ã§æå®ããã®ã§ã¯ãªããã¯ã©ã¹æå®ãªã©ãç¨ãã¦ãå¹çã®è¯ããããã³ã°ãè¡ããããã«ãã¾ãããã
.menuList ul li { ... }
.categoryList ol li { ... }
.checkList ul li { ... }
ä¾ãã°ä¸è¨ã®ãããªã¹ã¿ã¤ã«ã®å ´åã以ä¸ã®ããã«åli
è¦ç´ ã«ã¯ã©ã¹æå®ããæ¹ãããããã³ã°ã³ã¹ãã¯æãããã¾ãã
.menuList { ... }
.categoryList { ... }
.checkList { ... }
親è¦ç´ ããç¶æ¿ãããã¹ã¿ã¤ã«ããã¡ãã¨ç解ãã¦ãç¡é§ãªæå®ãçãã¾ãããã
.bookmark ul li { list-style-image: url(bookmarkIcon.gif); }
ä¾ãã°ãlist-style-image
ã¹ã¿ã¤ã«ã¯è¦ªè¦ç´ ããç¶æ¿ããã¾ãããã£ã¦ãä¸è¨ã®ã¹ã¿ã¤ã«ã¯ä»¥ä¸ã®ãããªæå®ã§ååã§ãã
.bookmark { list-style-image: url(bookmarkIcon.gif); }
äºç´°ãªãã¨ã®ããã«è¦ãã¾ãããul
è¦ç´ ãli
è¦ç´ ãæ°ç¾ãã£ãå ´åããã®æ°ç¾ã«å¯¾ãã¦ãã親è¦ç´ ãul
ã§ããã®å
ç¥ã"bookmark"ã¨ããã¯ã©ã¹ãæã¤è¦ç´ ã§ããããã¨ããæ¤è¨¼ãç¹°ãè¿ããã¨ã«ãªãã¾ããããã¯æãããã»ã©ã«ãããã³ã°ã³ã¹ããæããã¾ããæ¤è¨¼ãããã¹ããªã®ã¯ãã"bookmark"ã¨ããã¯ã©ã¹åãæã¤è¦ç´ ã®åè¦ç´ ãã ãã§ãã
Style Sheetã¯ã»ã¼å ¨ã¦ã®ä¸»è¦ãã©ã¦ã¶ã§ããã©ã¬ã«å¦çããµãã¼ãããã¦ãã¾ããããã«ãããä¾ãã°èªã¿è¾¼ã¿ã«1ç§æãããã¡ã¤ã«ã3ã¤ä½¿ãå ´åã§ãã3ãã¡ã¤ã«ã並åã«èªã¿è¾¼ãã®ã§ããã¼ã¿ã«1ç§ã§æ¸ã¿ã¾ãã
ããã@importã使ãå ´åããã©ã¬ã«å¦çããµãã¼ããããªãå¯è½æ§ãããã¾ãããã®å ´åã3ãã¡ã¤ã«ã¯é ã«èªã¿è¾¼ã¾ãããã¼ã¿ã«3ç§æãã£ã¦ãã¾ãã¾ãã
ã¾ããè¨è¿°æ¹æ³ã«ããåãã©ã¦ã¶ã®ãµãã¼ãç¶æ³ããããããªã®ã§ãå ´åã«ãã£ã¦ã¯ã¹ã¿ã¤ã«ãèªã¿è¾¼ã¾ããªãå¯è½æ§ãããã¾ãã
<head>
<style type="text/css">
@import url(/css/reset.css);
@import url(/css/common.css);
@import url(/css/font.css);
</style>
</head>
ä¸è¨ã®ãããªæå®ã¯ã以ä¸ã®ããã«link
è¦ç´ ã§æå®ãã¾ãããã
<head>
<link rel="stylesheet" type="text/css" href="/css/reset.css">
<link rel="stylesheet" type="text/css" href="/css/common.css">
<link rel="stylesheet" type="text/css" href="/css/font.css">
</head>
Putting a bunch of images into a single image file and selecting them with
-moz-image-region
performs significantly better than putting each image into its own file.
ã°ãã°ãã®ç»åã1ã¤ãã¤èªã¿è¾¼ããããã1ã¤ã®ç»åã«ã¾ã¨ãã¦è¡¨ç¤ºé åãæå®ãããã¨ã§ãããã©ã¼ãã³ã¹ã¯ãã£ã¨è¯ããªãã¾ãããã®æ¹æ³ãCSS Spriteã¨è¨ãã¾ããä¸è¨ã®å¼ç¨æã§ã¯ã-moz-image-region
ããããã£ã使ãããã«è¡¨è¨ããã¦ãã¾ãããMozillaã®ç¬èªæ¡å¼µã«ãªãã¾ãã
ä¾ãã°10åã®ç»åã使ç¨ãã¦ããå ´åãHTTPãªã¯ã¨ã¹ãã¯10ã§ããã1ã¤ã«ã¾ã¨ããå ´åããªã¯ã¨ã¹ãæ°ã¯1ã§æ¸ã¿ã¾ãã1,000ãã¤ãã®ç»åã10åèªã¿è¾¼ãã®ã¨ã10,000ãã¤ãã®ç»åã1ã¤èªã¿è¾¼ãã®ã¨ã§ã¯ã大åéã£ã¦ãã¾ãã
HTTPãªã¯ã¨ã¹ããæ¸ããã¨ãã観ç¹ã§è¨ãã°ãCSSãã¡ã¤ã«ãJSãã¡ã¤ã«ãªã©ãããã«å½ããã¾ãããã¡ã¤ã«ã¯ã§ããã ã1ã¤ã«ã¾ã¨ãã¾ãããã
ããã§è¨ããå¹ççãã¨ããã®ã¯ãããã¾ã§å®è¡æã®ããã©ã¼ãã³ã¹ã«ãã©ã¼ã«ã¹ãããã®ã§ããéç¨ãã¡ã³ããã³ã¹ãªã©ã®ç®¡çå¹çã¨ã¯ç¸åããå ´åããããã¨æãã¾ã(ãåå«ã»ã¬ã¯ã¿ã使ããªãããªã©)ãã¾ããHTMLå ã«ä½è¨ãªã¯ã©ã¹åããCSSã«ä½è¨ãªã¹ã¿ã¤ã«æå®ã追å ããªãã¨ãããªããªãå¯è½æ§ãããã¾ãããããªã£ã¦ãã¾ã£ã¦ã¯æ¬æ«è»¢åã§ãã
ããããªããããã¼ã¸ã®é«éåã¯ä½ããã®ã¦ã¼ã¶ããªãã£åä¸ã«ç¹ããã¾ãã管çå¹çãããã©ã¼ãã³ã¹ã¨ã®ãã©ã³ã¹ãä¸æãåããªãããããããã«åã£ã使ç¨ãã¿ã¼ã³ã確ç«ãã¦ããã¾ãããã