CSSã§ã¹ã¿ã€ãªã³ã°ãã
#2ã®è¬åº§ã§ã¯ãç°¡åãªhtmlãã¡ã€ã«ã®äœæãè¡ããŸãããä»åã¯CSSã䜿ã£ãŠhtmlãã¡ã€ã«ãã¹ã¿ã€ãªã³ã°ããããšæããŸãã
CSSã¯Cascading Style SheetsïŒã«ã¹ã±ãŒãã£ã³ã°ã»ã¹ã¿ã€ã«ã»ã·ãŒãïŒã®ç¥ã§ãããWebããŒãžïŒâHTMLïŒãè£ é£Ÿã»ã¹ã¿ã€ãªã³ã°ããããã®ã¹ã¿ã€ã«ã·ãŒãèšèªã§ãã
Cascadingã®æå³ã調ã¹ãŠã¿ããšãé£ç¶ãããã®ããæ°ç ç¹ãã«ãªã£ããã®ããšã®èª¬æããããŸããCSSã«ãããŠCascadingãã©ããã£ãæå³ãæã€ãã¯åŸãã説æããŸãããŸãã¯CSSã觊ã£ãŠã¿ãŸãããã
CSSãã¡ã€ã«ãäœæãã
ã§ã¯ãã£ãããã³ãºãªã³ãå§ããããšæããŸãã
ãŸãã¯ååäœæããindex.html
ãšåãéå±€ã«style.css
ãäœæããŠãã ãããstyle
ã®éšåã¯å€æŽå¯èœã§ããæ
£ç¿çã«style
ãçšããããŠããããšãå€ãã§ãããã ãæ¡åŒµåã§ãã.css
ã¯å€æŽäžå¯ã§ãããŸããcssãã¡ã€ã«ãhtmlãã¡ã€ã«ãšåæ§ã«æåã³ãŒãUTF-8
ãéžæããŠãã ããã
çŸåšããã©ã«ããŒæ§æã¯ä»¥äžã®ããã«ãªã£ãŠããŸãã
ãŸãã¯ãå床index.html
ãéããheadèŠçŽ å
ã«ä»¥äžã®ããã«linkèŠçŽ ãè¿œå ããŸãã
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./style.css" rel="stylesheet">
<title>Document</title>
</head>
<body>
<h1>Hello World</h1>
<p>ããã«ã¡ã¯ããã倩æ°ã§ããã</p>
<p>ä»æ¥ã¯ã飯ã§ãããããŸããã</p>
</body>
</html>
linkèŠçŽ ã¯å€éšãªãœãŒã¹ïŒä»åã®ãããªcssãã¡ã€ã«ïŒãæå®ããŠåã蟌ãããã®èŠçŽ ã§ããhref=ãã
ãšãã圢ã§ãèªã¿èŸŒãŸããããã¡ã€ã«ã®ãã¹ãèšè¿°ããŸãããã¹ãšã¯ããã¡ã€ã«ã眮ããŠããå Žæã®ããšã§ããä»åã¯htmlãã¡ã€ã«ãšåãå Žæã«cssãã¡ã€ã«ã眮ããŠããã®ã§./style.css
ãšããŸãïŒãã¹ã®æå®æ¹æ³ã¯å¥é詳ãã説æããŸãïŒã
ãã®åŸãã«rel="stylesheet"
ãšèšè¿°ããŠããŸãããããã¯èªã¿èŸŒãŸããããã¡ã€ã«ã®åœ¹å²ãæå®ãããã®ã§ãïŒrel
ã¯relationshipã®ç¥ïŒãcssãã¡ã€ã«ãèªã¿èŸŒãŸããŠããã®ã§stylesheet
ãšèšè¿°ããŸãããã®äžæã¯cssãã¡ã€ã«ãèªã¿èŸŒãŸããæã®å®åæã¿ãããªãã®ã§ããæå³ãç解ããŠèŠããŠãããŸãããã
以äžãè¿œèšãããindex.html
ãã¡ã€ã«ãäžæžãä¿åããŸãã
èæ¯è²ãå€æŽãã
ã§ã¯ãããããcssãã¡ã€ã«ã®ç·šéã«åãæãããŸãããŸãã¯èæ¯è²ãéè²ã«å€æŽããŠã¿ãŸãããã
style.css
ã«ä»¥äžã®ããã«èšè¿°ããŠãã ããã
@charset "UTF-8";
body {
background-color: lightblue;
}
èšè¿°åºæ¥ããcssãã¡ã€ã«ãäžæžãä¿åããŸãããããŠhtmlããŒãžãéããšä»¥äžã®ããã«ãç»é¢å šäœãèãéè²ã«å€åããŠããã¯ãã§ãã
ããã§cssãã¡ã€ã«ãäœæããhtmlãã¡ã€ã«ã«èªã¿èŸŒãŸããWebããŒãžãã¹ã¿ã€ãªã³ã°ããããšã«æåããŸããðððã
ãããäžæããããªãïŒããŒãžã®èæ¯è²ãå€ãããªãïŒå Žåã«ã¯ãããäžåºŠãããŸã§ã®æé ãèŠçŽããæ£ç¢ºã«èšè¿°ã§ããŠãããã確èªããŠãã ããã
倱æã®åå ã«ã¯æ§ã ãªããšãèããããŸããããã®äžã€äžã€ã®å 容ã詳ããèšè¿°ããã«ã¯äœçœã足ããŸãããç°¡åãªãã§ãã¯ãªã¹ããçšæããŸããã®ã§äžããé çªã«èŠãŠãã£ãŠãã ããã
- â
ç®çã®
index.html
ããã©ãŠã¶ãŒã«è¡šç€ºããŠãããïŒïŒééã£ãŠéãhtmlãã¡ã€ã«ã衚瀺ãããŠããªããïŒïŒ - â
style.css
ãç·šéããåŸãindex.html
ãåèªã¿èŸŒã¿ãããïŒ - â
index.html
ãšåããã©ã«ãã«style.css
ãäœæãããïŒ - â
index.html
ã®headå±æ§ã«linkå±æ§ãè¿œèšãããïŒ - â
index.html
ã®linkå±æ§ã®href="./style.css"
ã¯æ£ãããïŒ - â
index.html
ã®linkå±æ§ã®rel="stylesheet"
ã¯æ£ãããïŒ - â
style.css
ã®å 容ã¯æ£ãããïŒ
çœç¶ãããšãç§ããCSSãé©çšãããªãã ããŒð¿ããšãªãããšãå幎ã«äžåããããããŸããããããPCããã©ãŠã¶ãŒã®ãã°ãšããå¯èœæ§ã¯ã»ãšãã©ãªãã®ã§ããã¡ãåŽã§äœãã±ã¢ã¬ã¹ãã¹ããŠããã¯ãã§ãã泚ææ·±ã確èªããŸãããã
æåã®ã¹ã¿ã€ã«ãè²ã å€æŽããŠã¿ã
现ããããšã¯åŸåãã«ããŠãæåã®è²ã倧ããã«ã€ããŠãå€æŽããŠã¿ãŸããstyle.css
ã«ä»¥äžãè¿œèšããŠãã ããã
(ç¥)
h1 {
color: green;
}
p {
color: red;
font-size: 10px;
}
äœãããŠããã¯äœãšãªãåãããšæããŸãããããŒãžããªããŒããããšä»¥äžã®ããã«å€åããŠããã¯ãã§ãã
CSSã®æžãæ¹
ã§ã¯ãstyle.css
ã®äžèº«ãèŠãªãããCSSã®æžãæ¹ã説æããŸãã
ãŸã1è¡ç®ã«ã¯æåã³ãŒããæå®ããŸããããã®ãã¡ã€ã«ã®æåã³ãŒãã¯UTF-8ã§æžãããŠããŸãããšããããšã宣èšããããã®äžæã§ãã
@charset "UTF-8";
style.css
ã¯UTF-8ã§ä¿åããŸããã®ã§ãåæ§ã«UTF-8ãæå®ããŸãããã®äžæã¯å¿
ãcssãã¡ã€ã«ã®å
é ã«èšè¿°ããå¿
èŠããããŸãã
ã»ã¬ã¯ã¿ãŒ
CSSã¯ãã©ã®èŠçŽ ã®ã©ã®èŠãç®ãã©ããªé¢šã«è¡šç€ºããããšãã颚ã«æå®ããŠèšè¿°ããŠãããŸãããã®äžã§ãã©ã®èŠçŽ ããè¡šãã®ãã»ã¬ã¯ã¿ãŒãšåŒã°ããŠããéšåã§ããå
·äœçã«ã¯ãbody
ãh1
ãp
ãåœãŠã¯ãŸããŸãã
ãã©ã®èŠçŽ ãã»ã¬ã¯ããããããã ããã»ã¬ã¯ã¿ãŒã§ããèŠããããã§ããã
ã»ã¬ã¯ã¿ãŒãèšè¿°ããããæ³¢æ¬åŒ§{}
ãèšè¿°ããŸãã{
ãš}
ã®éã«ã次ã«çŽ¹ä»ããããããã£ãšå€ãèšè¿°ããŸãã
body {
/* bodyèŠçŽ ã®ã¹ã¿ã€ã«ãæå® */
}
h1 {
/* h1èŠçŽ ã®ã¹ã¿ã€ã«ãæå® */
}
p {
/* pèŠçŽ ã®ã¹ã¿ã€ã«ãæå® */
}
ããããã£
次ã«ãæå®ããèŠçŽ ã®ãã©ã®èŠãç®ãã«è©²åœããããããã£ãèšè¿°ããŸãã
bodyèŠçŽ ã§ã¯background-color
ããããã£ãèšè¿°ããŠããŸããããã¯èæ¯è²ãæå®ããããããã£ã§ãã
h1èŠçŽ ã§ã¯color
ããããã£ãèšè¿°ããŠããŸããããã¯æåã®è²ãæå®ããããããã£ã§ãã
pèŠçŽ ã§ã¯font-size
ããããã£ãèšè¿°ããŠããŸããããã¯æåã®å€§ãããæå®ããããããã£ã§ãã
ãããŠãããããã£ã®åŸãã«ã¯ã³ãã³:
ãèšè¿°ããŸãããã®ã³ãã³ã®åŸãã«å€ãèšè¿°ããŸãã
body {
/* èæ¯è²ãæå® */
background-color:
}
h1 {
/* æåã®è²ãæå® */
color:
}
p {
/* æåã®è²ãæå® */
color:
/* æåã®å€§ãããæå® */
font-size:
}
ããããã£ã«ã¯éåžžã«å€ãã®çš®é¡ããããå šãŠãèŠããã®ã¯äžå¯èœã§ãããšèšã£ãŠããäžèšäŸããåããéããããããã£ã®ååã¯ãšãŠã説æçã§çŽæçã«åãããããããã代衚çãªãã®ã¯ãããªã«èŠåŽããã«èŠããããã§ãããã
å€
æåŸã«ãå ·äœçã«ã©ã®ããã«ã¹ã¿ã€ãªã³ã°ãããã®å€ãèšè¿°ããŸããå€ã«ã©ã®ãããªãå€ããå ¥ãããããã¯ããããã£ããšã«éããŸãããããå°éã«èŠããŠãããããããŸããã
background-color
ãšcolor
ã«ã¯è²ãæå®ããå€ãå
¥ããŸããè²ã®æå®ã«ã¯æ§ã
ãªæ¹æ³ããããŸãããããã¯ãšããããçŽæçã«åãããããlightblue
ãgreen
ãred
ãªã©ãšããŠããŸãã
font-size
ã«ã¯æåã®å€§ãããæå®ããæ°åãå€ãšããŠå
¥ããŸãã倧ããã«ãæ§ã
ãªæå®æ¹æ³ããããŸãããããã§ã¯pxïŒãã¯ã»ã«ïŒãšããåäœã䜿ã£ãŠæå®ããŸãã
ãããŠå€ã®åŸãã«ã¯ã»ãã³ãã³;
ãèšè¿°ããå€ãèšè¿°ããããšãæ瀺ããŸãã
/* bodyèŠçŽ ã®èæ¯è²ãæããéè²ã«ãã */
body {
background-color: lightblue;
}
/* h1èŠçŽ ã®æåãç·è²ã«ãã */
h1 {
color: green;
}
/* pèŠçŽ ã®æåãèµ€è²ã«ããæåã®å€§ããã10ãã¯ã»ã«ã«ãã */
p {
color: red;
font-size: 10px;
}
以äžãCSSã®ã»ã¬ã¯ã¿ãŒ
ãããããã£
ãå€
ã®èª¬æã§ãããã®äžã€ã®åèªã¯ããããããã·ãã·åºãŠããã®ã§ãæãåºããããã«ããŠãããŠãã ããã
HTMLãCSSã®è¶ åºæ¬ã¯ä»¥äž
ããŠãååãšä»åã«ããã£ãŠHTMLãšCSSãã©ããªãã®ã§ãããã説æããŠããŸããã
ããããHTMLãšCSSã«ã€ããŠã®çŽ°ããéšåãåŠç¿ããŠãããŸããããããŸã§ã«çŽ¹ä»ãããhtmlãã¡ã€ã«ã«èŠçŽ ãèšè¿°ãcssãã¡ã€ã«ã§èŠçŽ ãæå®ããŠã¹ã¿ã€ãªã³ã°ããããšããæ ¹æ¬çãªéšåã¯å€ãããŸããã
次ããã¯ãã°ããCSSã¯ãäŒã¿ããŠãHTMLã®åºç€ãåŠç¿ããŠãããããšæããŸãã