https://mosya.dev/lessons/speech-bubble/challenge
CSSã§ãµãã ããäœãããšããŠããŸãã
ãµãã ãã®åè§ã®éšåããªããã®ã³ãŒãã«ãªãã®ãç解ã§ããŸããã
.speech-bubble:before {
content: "";
position: absolute;
top: -20px;
left: 50px;
border: 10px solid transparent;
border-bottom-color: #506975;
}
ãã¡ãã®ã³ãŒãã¯:before
ç䌌èŠçŽ ã䜿çšããŠããµãã ãã®äžè§éšåãäœæãããã®ã§ãããã®äžè§éšåãäœæããããã«ã¯ãããŒããŒã®ç¹æ§ãå©çšãããã¯ããã¯ã䜿ãããŠããŸãã
top
, left
ãªã©ã®ããããã£ã§äœçœ®ã調æŽã§ããŸãã#506975
ã«å€æŽããŸããããã«ãããäžéšã®ããŒããŒã ããæå®ããè²ãšãªããä»ã®3蟺ã¯éæã®ãŸãŸã§ãããã®ãã¯ããã¯ãå©çšãããšãå®éã«è¡šç€ºãããã®ã¯äžéšã®ããŒããŒã ãã§ãããã®ããããµãã ãã®éšåã«åãã£ãŠããäžè§åœ¢ãšããŠèŠããããšã«ãªããŸãã
èŠç¹ãšããŠã¯ãborder
ã®ç¹æ§ãå©çšããŠåè§åœ¢ã®äžéšã ãã衚瀺ããããšã§ãäžè§åœ¢ãäœæããŠããããšããããšã§ãã
ãªãäžè§ã«ãªããã§ããïŒ:before
ã¯å
ã
ã©ããªåœ¢ãªãã§ããïŒ
borderãtransparentã«ããŠéæã«ããåŸborder-bottomã§è²ãã€ãããšãªããšç·ã«ãªãæ°ãããŠãªããŸããã
ãŸãã:before
ç䌌èŠçŽ èªäœã¯ãåºæ¬çã«ãããã¯ã¹ããšããŠçæããããã®ã§ããå
·äœçãªåœ¢ç¶ã倧ããã¯æå®ããªãéã0x0ã®å€§ããã«ãªããŸããããããborder
ã䜿çšããããšã§ãã®ããã¯ã¹ã«ç¹å®ã®å€§ãããæãããããšãã§ããŸãã
次ã«ãborder
ã®ç¹æ§ã«é¢ããŠèª¬æããŸããéåžžãããŒããŒã¯åæ¹ã®ç·ãšããŠèãããããããããŸããããå®éã«ã¯ããããã®ããŒããŒã¯åè§åœ¢ã®äžéšãšããŠæç»ãããŸãããããäžè§åœ¢ãäœæããéã®ããŒãã€ã³ãã§ãã
以äžã®ã€ã¡ãŒãžãèããŠã¿ãŠãã ããã
ãã®æãäžã®èŸºã ããè²ä»ãã§ãä»ã®3蟺ã¯éæãªã®ã§ãèŠãç®ãšããŠã¯äžè§åœ¢ã圢æãããããã«èŠããŸãã
å®éã«ãborder
ã䜿çšããŠãã®ãããªåœ¢ç¶ãäœæããéã®ãã€ã³ãã¯ãåæ¹ã®ããŒããŒãããããç¬ç«ããåè§åœ¢ãšããŠæç»ãããããšããããšã§ãããããã£ãŠãborder
ã®3蟺ãéæã«ããæ®ã1蟺ã«ã ãè²ãã€ããããšã§ãäžè§åœ¢ãäœæããããšãã§ããŸãã
äŸã®CSSã§ã®èšå®ãèŠããš:
border: 10px solid transparent;
border-bottom-color: #506975;
ãã®èšå®ã«ãããäžã»å·Šã»å³ã®ããŒããŒã¯éæã«ãªããäžã®ããŒããŒã ãã#506975
ã®è²ãæã¡ãŸããçµæãšããŠãäžã®ããŒããŒéšåã ããèŠããããšã«ãªãããããäžè§åœ¢ãšããŠæç»ãããŸãã
ã¯ããã®å€§ããªæ£æ¹åœ¢ã¯è²ãå¡ãããç¶æ
ãã€ã¡ãŒãžãããšããããšã§ããïŒ
äžãå·Šãå³ã®ïŒèŸºãéæã«ããŠäžã ãè²ãã€ããããå¡ãé¢ç©ãç¡ããªãæ°ãããŸãããªãäžè§åœ¢ã®é ç¹ãããã®ã§ããããïŒ
ããŒããŒãçšããŠäžè§åœ¢ãäœæããéã®ãã€ã³ãã¯ãããŒããŒãå®éã«ã©ã®ããã«æç»ãããããç解ããããšã§ããborder
ã®å蟺ã¯ãåãªãçŽç·ã§ã¯ãªããå®ã¯ãåè§åœ¢ããšããŠæç»ãããŸããããã¯ã¹ã®ããŒããŒãååããããšãããã¯åè§åœ¢ã®é¢ãšããŠæç»ãããããšã«ãªããŸãã
äŸãã°ãåè§åœ¢ããã¯ã¹ãèãããã®ããŒããŒã®å¹ ã10pxã«ããå Žåãããã¯ã¹ã®å蟺ã«ã¯ã10pxã®å€ªãã®åè§åœ¢ãè¿œå ãããŸãããã®æãããã¯ã¹ã®4蟺ããããã«ãåè§åœ¢ãšããŠã®ããŒããŒãååšããŸãã
ããã§ãäžã»å·Šã»å³ã®ããŒããŒãéæã«ããäžã®ããŒããŒã ãã«è²ãä»ãããšãäžã®ããŒããŒã ãã衚瀺ãããããšã«ãªããŸãããã®æãäžã®ããŒããŒã¯åè§åœ¢ã®åœ¢ã§ã¯ãªããäžè§åœ¢ã®åœ¢ãšããŠè¡šç€ºãããŸãã
ãªããªããäžã»å·Šã»å³ã®ããŒããŒãéæã§ãããããäžã®ããŒããŒã®åè§åœ¢ãããããšåäœããŠãäžè§åœ¢ãšããŠæç»ãããããã§ãã
å ·äœçã«ã¯ãäžã®ããŒããŒã®å·Šç«¯ãšå³ç«¯ã¯ãå·ŠããŒããŒãšå³ããŒããŒãšåäœããããšã§ãäžè§åœ¢ã®æ蟺ãšãªããŸãããããŠãäžã®ããŒããŒã®äžç«¯ã¯ãäžè§åœ¢ã®åºèŸºãšãªããŸãã
äžã®ããŒããŒã®äž¡ç«¯ã¯å·ŠããŒããŒãšå³ããŒããŒã«åçŽé¢ä¿ã ã£ãã®ããéæã«ããããšã§è§åºŠãããããšããããšã§ããïŒ
ã¯ããæ£ç¢ºã«ã¯ãã®ããã«è¡šçŸããã®ãããé©åã§ãã
ããã¯ã¹ã®ããŒããŒãååããããšãããããã®ããŒããŒã¯å®éã«åè§åœ¢ã®é åãšããŠååšããŸãããã®åè§åœ¢ã®é åã®é£æ¥ãã蟺å士ïŒäŸãã°ãäžã®ããŒããŒã®å·Šç«¯ãšå·Šã®ããŒããŒã®äžç«¯ïŒãæ¥è§ŠããŠããŸãã
åæ¹ã®ããŒããŒããã¹ãŠåãè²ã倪ããæã£ãŠããå Žåããããã®èŸºå士ã®æ¥è§Šéšåã¯ç®ç«ããªããªããŸããããããäžéšã®ããŒããŒãéæã«ãããšãæ¥è§Šéšåãç®ç«ã£ãŠããŸãã
å ·äœçã«ãäžã»å·Šã»å³ã®ããŒããŒãéæã«ããäžã®ããŒããŒã ãã«è²ãä»ããå Žåãäžã®ããŒããŒã®å·Šç«¯ãšå³ç«¯ã¯ãããããå·ŠããŒããŒãšå³ããŒããŒã®é åã«æ¥è§ŠããŠããéšåãšããŠè¡šç€ºãããŸãããã®æ¥è§Šéšåãæ蟺ãšããŠè¡šç€ºãããçµæãšããŠäžè§åœ¢ã圢æãããããã§ãã
ãã®ããã«ãããŒããŒã®ç¹æ§ãç解ããé©åã«è²ã倪ãã調æŽããããšã§ãããŸããŸãªåœ¢ç¶ããã¶ã€ã³ãå®çŸããããšãã§ããŸãã
ããŒããŒãéæã«ãªããšåè§åœ¢ã®é åã«å€åãèµ·ãããšããããšã§ããïŒ
ããããããŒããŒãéæã«ãªãããšã§åè§åœ¢ã®é åãã®ãã®ã«å€åãçããããã§ã¯ãããŸãããããããæã ããããèŠèŠçã«ã©ã®ããã«è§£éããããå€ãã£ãŠããŸãã
å ·äœçã«ã¯ãããŒããŒã®é åãã®ãã®ã¯åè§åœ¢ãšããŠåžžã«ååšããŸããããããéæãªããŒããŒã¯èŠèŠçã«ã¯ãååšããªãããšæããããŸãããã®ãããè²ä»ãã®ããŒããŒã®éšåã ããç®ç«ã¡ããããç¹å®ã®åœ¢ç¶ãšããŠè§£éãããããšã«ãªããŸãã
ããŒããŒã䜿ã£ãäžè§åœ¢ã®ãã¯ããã¯ã«ãããŠã以äžã®æé ã§èŠèŠçãªäžè§åœ¢ã圢æãããããšãèããŠã¿ãŸãããã
ããŒããŒã®åè§åœ¢ã®é åãã®ãã®ã¯å€åããŠããªãã®ã§ãããéæãšè²ä»ãã®éšåãšã®çµã¿åããã«ãããæã ã¯ãããäžè§åœ¢ãšããŠèŠãããšããã®ããã®ãã¯ããã¯ã®ãã€ã³ãã§ãã
> 䞡端ãæãã«ã«ãããããããã«èŠãã
ãã®éšåãããå°ã詳ãã解説ããŠãã ããã
äºè§£ããŸãããããŒããŒãçšããäžè§åœ¢ã®åœ¢æã«é¢ããŠãç¹ã«ã䞡端ãæãã«ã«ãããããããã«èŠããããšããç¹ãäžå¿ã«è§£èª¬ããŸãã
ãŸããããã¯ã¹ã¢ãã«ã®ããŒããŒã¯ãå®éã«ã¯åè§åœ¢ã®é¢ãšããŠæç»ãããããšãç解ãããšããããå§ããŸãããã®åè§åœ¢ã®é¢ã®åœ¢ææ¹æ³ã¯ãããŒããŒã®å€ªãã«äŸåããŸããäŸãã°ãããŒããŒã10pxã®å Žåãããããã®ããŒããŒã¯10pxã®å¹ ã®åè§åœ¢ã®é¢ãšããŠååšããŸãã
以äžã®ã¹ãããã§äžè§åœ¢ãã©ã®ããã«åœ¢æããããã詳ããèŠãŠãããŸãïŒ
ãã®ããã«ãéæãªããŒããŒãšè²ä»ãã®ããŒããŒã®äº€å·®ç¹ã§ãæãã®ç·ïŒäžè§åœ¢ã®æ蟺ïŒã圢æãããããšãããã®ãã¯ããã¯ã®ããŒãã€ã³ãã§ãã
> ããŒããŒã®åè§åœ¢ã®é¢ãéãªãåããæãã®ç·ãšããŠè§£éãããããã«èŠããŸãã
ãã®éšåãåãããŸãããããå°ã詳ããæããŠãã ãã
ããŒããŒã䜿ã£ãäžè§åœ¢ã®çæã«é¢ããŠããã®ããŒã³ã³ã»ãããç解ããããã«ãããã¯ã¹èªäœãéæãªå®¹åšãšèããŠã¿ãŠãã ãããããŒããŒã¯ãã®å®¹åšã®åšããåãå²ãã§ããŸãã
border: 10px solid black;
ãšããã¹ã¿ã€ã«ããããšãããã¯ã¹ã®å蟺ã«ã¯10pxã®å€ªãã®ãåè§åœ¢ã®é¢ããšããŠé»ã®ããŒããŒãååšããŸããèŠããã«ãéæãªããŒããŒãååšããããšã§ãè²ãæã€ããŒããŒã®åè§åœ¢ã®é¢ã®äžéšããé ããŠããããšæããããã®ã§ããããããæãã«ã«ãããããããã«èŠããããšæããçç±ãšãªããŸãã
> æãã«ã«ãããããããã«èŠãã
ãã®éšåã¯ç解ã§ããŸãããã§ããããªãé ç¹ã«ãªãã®ããåãããŸããã
äºè§£ããŸããããã®éšåã«ã€ããŠèª¬æããŸãã
ããã¯ã¹ã®ããŒããŒãçšããäžè§åœ¢ã®ãã¯ããã¯ã«ãããŠãããŒããŒã¯å®éã«ã¯åè§åœ¢ã®é åãšããŠæç»ãããŸãããããã£ãŠãå·Šã»å³ã»äžã®ããŒããŒãèããå Žåããããããç¬ç«ããåè§åœ¢ãšããŠååšããŸãã
äžã®ããŒããŒã«è²ãä»ããå Žåãããã¯åè§åœ¢ã®åž¯ã®ããã«èŠããŸããéæãªå·Šã»å³ã®ããŒããŒã¯ãèŠèŠçã«èŠããªãããããã®ååšãå¿ããããšã容æã§ãããããããããã®éæãªããŒããŒã¯å®éã«ã¯ååšããäžã®ããŒããŒãšé£æ¥ããŠããŸãã
äžã®ããŒããŒã®å·Šç«¯ã¯ãå·ŠããŒããŒã®äžç«¯ãšæ¥è§ŠããŠãããäžã®ããŒããŒã®å³ç«¯ã¯ãå³ããŒããŒã®äžç«¯ãšæ¥è§ŠããŠããŸãã
éæãªããŒããŒã¯ãååšããªãããšããŠèªèããããããäžã®ããŒããŒã®å·Šç«¯ãšå³ç«¯ã¯ã空äžãã§çµãã£ãŠãããã®ããã«èŠããŸãããããããããã®ç«¯ã¯ãå®éã«ã¯éæãªããŒããŒã®é¢ãšæ¥è§ŠããŠããããã®æ¥è§Šç¹ããé ç¹ããšããŠèªèãããã®ã§ãã
ã€ã¡ãŒãžãšããŠã¯ãäžã®ããŒããŒããå°é¢ãã§ãéæãªå·Šã»å³ã®ããŒããŒããå£ããšèããããŸããäžã®ããŒããŒã®ç«¯ãããããã®ãå£ãã«æ¥è§ŠããŠããããã®æ¥è§Šç¹ããé ç¹ããšããŠèŠèŠçã«è§£éãããŸãã
äžã®ããŒããŒãšã®æ¥è§Šéšåãé ç¹ã«ãªãããšã¯ç解ããŠããŸãã
éæãªå·ŠããŒããŒãšå³ããŒããŒäº€ç¹ãé ç¹ã«ãªãæå³ãåãããŸãããå°åœ¢ã«ãªããŸãããïŒïŒ
ç³ãèš³ããããŸãããååã®èª¬æã§ééãããããŸããããã£ããããšãããéæãªå·ŠããŒããŒãšå³ããŒããŒã®äº€ç¹ãé ç¹ã«ãªãããã§ã¯ãããŸãããæ£ç¢ºã«ã¯ãéæãªå·ŠããŒããŒã®äžç«¯ãšãè²ä»ãã®äžããŒããŒã®å·Šç«¯ãæ¥è§Šããç¹ããããŠéæãªå³ããŒããŒã®äžç«¯ãšãè²ä»ãã®äžããŒããŒã®å³ç«¯ãæ¥è§Šããç¹ããã®2ç¹ãäžè§åœ¢ã®é ç¹ãšããŠèªèãããŸãã
å床ãããŒããŒãçšããŠäžè§åœ¢ãçæããéã®ä»çµã¿ã説æããããŸãã
CSSã®ããŒããŒã¯ãããã¯ã¹ã®å蟺ã«åè§åœ¢ã®ãé¢ããšããŠæç»ãããŸããéæãªããŒããŒã¯èŠèŠçã«èŠããªããããããã¯ã¹ã®å 容éšåãšè²ä»ãã®ããŒããŒéšåã®ã¿ãç®ç«ã¡ãŸãã
äŸãšããŠã以äžã®ã¹ã¿ã€ã«ãæã€ããã¯ã¹ãèããŠã¿ãŠãã ããã
box-sizing: border-box;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
ãã®å Žåã以äžã®ããšãèµ·ãããŸãïŒ
ãã®ç¶æ ã§ãéæãªå·ŠããŒããŒã®äžç«¯ãšèµ€ãäžããŒããŒã®å·Šç«¯ãæ¥è§Šããéæãªå³ããŒããŒã®äžç«¯ãšèµ€ãäžããŒããŒã®å³ç«¯ãæ¥è§ŠããŸãããã®æ¥è§Šéšåãäžè§åœ¢ã®2ã€ã®é ç¹ãšããŠåœ¢æãããã®ã§ãã
ãããŠãéæãªããŒããŒéšåã¯èæ¯ãä»ã®ã³ã³ãã³ãã«é ãããããçµæçã«äžã®èµ€ãããŒããŒéšåã ããèŠããŠäžè§åœ¢ãšããŠèªèãããã®ã§ãã
ãææããã ãããããšãããããŸãã誀解ãæã説æãããŠããŸããç³ãèš³ããããŸããã
ããŒããŒã®é·ãã¯ããã€ã«èšå®ããŠããã®ãæ³å®ããŠããŸããïŒ
å·ŠããŒããŒã«æ¥è§Šãããããã«ããŠå³ããŒããŒãèšçœ®ããäžäžããŒããŒãåæ§ã«é
眮ãã圢ããåè§åœ¢ã®é åããšå®çŸ©ããŠãããã§ããããïŒ
ä»ãŸã§ãåè§ã®boxã®åæ¹åã«æ¥ããããã«ããŠããŒããŒã眮ãããŠããã®ããšåéãããŠããŸããã
ç³ãèš³ããããŸãããæ··ä¹±ãæã説æã«ãªã£ãŠããŸã£ãããã§ãã
ãŸãåºæ¬ãããäŒãããŸããéåžžãããŒããŒã¯ç¢ºãã«ããã¯ã¹ã®åæ¹ã«æ¥ããããã«é 眮ãããŸããå ·äœçã«ã¯ãèŠçŽ ã®ã³ã³ãã³ãããã¯ã¹ã®å€åŽã«ããã£ã³ã°ããã¯ã¹ãããŒããŒããã¯ã¹ãããŒãžã³ããã¯ã¹ãé ã«ååšããŸãã
ãããããã®ããŒããŒãçšããŠäžè§åœ¢ãçæãããã¯ããã¯ã§ã¯ãããŒããŒã®ãåè§åœ¢ã®é¢ãã匷調ããŠç解ããããšãéµãšãªããŸãã
å床ãäžè§åœ¢ã圢æããããã®åºæ¬çãªèãæ¹ãæŽçããŠã¿ãŸãããã
å ·äœçã«ã以äžã®ãããªã³ãŒããèããŠã¿ãŠãã ããã
.triangle {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
}
ãã®ã³ãŒãã«ãããŠãå·Šã»å³ããŒããŒã¯ãããã50pxã®å¹ ãæã¡ãäžããŒããŒã¯100pxã®é«ããæã¡ãŸãããããŠããããã®ããŒããŒãåäœããããšã§ãäžåãã®äžè§åœ¢ã圢æãããŸãã
ãã®ãã¯ããã¯ã§ã¯ãå®éã«ã¯ããŒããŒã®ãåè§åœ¢ã®é¢ããéãªãåã£ãŠäžè§åœ¢ã圢æããŠããŸããã§ãã®ã§ãåæ¹åã«æ¥ããããŒããŒãåè§åœ¢ã®é åãšããŠååšãããã®éãªãåãéšåãäžè§åœ¢ã圢æããããšããç解ã§æ£ç¢ºã§ãã
ãã£ãããéããå·ŠããŒããŒã®äžç«¯ãšäžããŒããŒã®å·Šç«¯ãå³ããŒããŒã®äžç«¯ãšäžããŒããŒã®å³ç«¯ãæ¥è§ŠããŠãããšèããããšãã§ããŸãããããŠããããäžè§åœ¢ã®é ç¹ãšããŠèŠããçç±ãšãªããŸãã
æå³åãããŸããïŒããããšã
è¯ãã£ãã§ãïŒæ··ä¹±ãæã説æã«ãªã£ãŠããŸã£ãéšåããããç³ãèš³ããããŸããã§ããã
CSSã®ãã¯ããã¯ãä»çµã¿ã¯ç¬ç¹ãªéšåãå€ããããæã çŽæçã«ç解ãã«ããéšåããããŸãããå ·äœçãªã³ãŒããããããªããè©ŠããŠã¿ããšãããç解ãæ·±ãŸãããšãå€ãã§ãã
äœãä»ã«ã質åãçåç¹ããããŸãããããã€ã§ããæ°è»œã«ã質åãã ããããæäŒãã§ããããšãããã°å¹žãã§ãã
mosyaã®ã³ãã¥ããã£ã§äžè§åœ¢ãé 匵ã£ãããšãæçš¿ããŠã¿ããããããªããšãæããŠããããŠãã³ããªâ€(ÓŠïœÓŠïœ¡)
ãã®èšäºã®äžã«ãã£ãtanΞã®ãã ããæããããªã£ãŠæãåºãããŠãèšç®ããŠã¿ãã
â
ã³ãã¥ããã£ã£ãŠçŽ æµã ãªãšæããŸããâ¡(*Ž·Ï·)(·Ï·`*)â¡