Tailwindcssã¨ã¯
CSSã©ã¤ãã©ãªã®ä¸ç¨®ã
BootstrapãBulmaã®ãããªä»ã®CSSã©ã¤ãã©ãªã¨ç°ãªãã
.btn
ã.card
ã¨ãã£ãã³ã³ãã¼ãã³ãç³»ã®ã¯ã©ã¹ã¯å®ç¾©ããã¦ãããã
<b>1ã¤ã®ã¹ã¿ã¤ã«ã®ã¿ãå¤æ´ããã¦ã¼ãã£ãªãã£ç³»ã®ã¯ã©ã¹ãããããè©°ã¾ã£ã¦ãã</b>ã®ãç¹å¾´ã
Tailwindcssã§å®ç¾©ããã¦ããã¯ã©ã¹ã®ä¾:
.font-bold { font-weight: 700; }
.rounded { border-radius: .25rem; }
.hidden { display: none; }
ãã®ç¹æ§ãWebéçºã§ä¸ä½ã©ããªå¹æãããããã®ãï¼ Webéçºã§ã¯ããªãã¿ã®Bootstrapã¨æ¯è¼ããªããå¦ãã§ãããã
Bootstrap vs Tailwindcss : ãã¿ã³ã®ä¾
Bootstrapã使ã£ã¦ãããªãããã¿ã³ãå®è£ ããã®ã¯ä»¥ä¸ã®ããã«ããã°ããã ãã ã
<button class="btn btn-primary">
Button
</button>
ä¼¼ããããªãã¿ã³ãTailwindcssã§ä½ããªãã以ä¸ã®ããã«ãªãã ããã
<button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded select-none">
Button
</button>
Bootstrapã¯ããã2åã®ã¯ã©ã¹ãæå®ããã ãã§ãããæãã®ãã¿ã³ãã§ããã ä¸æ¹ã§ãTailwindcssã¯è²ã ã¨ã¦ã¼ãã£ãªãã£ã¯ã©ã¹ãæå®ãã¦ãããããã¿ã³ãåºæ¥ä¸ãã£ã¦ããã
ä¸è¦ããã¨ãBootstrapã®æ¹ãç°¡åã ãè¦éããããã Tailwindcssã®ã»ãã¯ãã¡ãã¡ããããã¯ã©ã¹ãæ¸ããªãããã¡ã ããé¢åããããã ãªâ¦ã¨æããããããããªãã
ãããããããããTailwindcssã®æ¬é ã ã
ã«ã¹ã¿ãã¤ãºæ§
Bootstrapã使ã£ã¦ãããµã¤ãã¯å¤ãã¨ã¯ãããå ¨ãã«ã¹ã¿ãã¤ãºããªãã§ä½¿ã£ã¦ãããµã¤ãã¯ããã»ã©å¤ããªãã ãããå¤ããå°ãªãããã¦ã¼ã¶ã¼å®ç¾©ã«ããCSSã«ããå ã®ã¹ã¿ã¤ã«ãæ¸ãæãããã¦ããå ´åãå¤ãã¯ãã§ããã
ããã§ãå ã»ã©ã®ãã¿ã³ãã«ã¹ã¿ãã¤ãºãã¦ã¿ããã ä¸ä¸ã®ä½ç½ã大ãããã¦ãæåã大ãã太ããã¦ãæ¨ªå¹ ãã£ã±ãã«åºããããã«ãã¦ã¿ãã
Bootstrapã®ããã¥ã¡ã³ããè¦ãã¨ã
btn-block
ãæå®ããã°æ¨ªå¹
ãã£ã±ãã«åºããããã ã
ãããä½ç½ã¨æåã«é¢ãã¦ã¯èªåã§CSSãæ¸ããªãã¡ããããªããããã
ã¨ãããã¨ã§ãCSSãã¡ã¤ã«ã«ãã¿ã³ã«é¢ããã¯ã©ã¹ã追å ããã
.btn-custom {
font-size: 1.5rem;
font-weight: 700;
padding-top: 1.0rem;
padding-bottom: 1.0rem;
}
HTMLã以ä¸ã®æ§ã«æ¸ãæããã
<button class="btn btn-primary btn-custom btn-block">
Button
</button>
ã«ã¹ã¿ã ããåã¨æ¯ã¹ãã¨ãHTMLã§æå®ããã¯ã©ã¹ã2ã¤å¢ãã¦ãCSSã«ã¦ã¼ã¶ã¼å®ç¾©ã®ã¯ã©ã¹ã1ã¤å¢ããã ããããã¦ã¼ã¶ã¼å®ç¾©ã®ã¯ã©ã¹ã¯ãã§ã«ã¹ã¿ã¤ã«ãå®ç¾©ããã¦ããã¯ã©ã¹ã¨ååãè¡çªããªãããã«æ°ãã¤ãã£ã¦ååãã¤ããªãã¦ã¯ãããªããååãè¡çªããã¨ãæ¬æ¥ç¡é¢ä¿ã®è¦ç´ ã¾ã§ã¹ã¿ã¤ã«ãæ¸ãæãã£ã¦ãã¾ãæããããããã ã
ã«ã¹ã¿ã ããåã¯ã¨ã¦ãç°¡åã«æããHTMLããæå®ããã¯ã©ã¹ã¯å¢ãã¦ç¬èªå®ç¾©ã®CSSã®é¢åã¾ã§è¦ãªããã°ãããªããªã£ãã®ã ã
ä»åº¦ã¯Tailwindcssã®ã»ãã§åæ§ã®ã«ã¹ã¿ãã¤ãºããã£ã¦ã¿ããã
<button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-4 rounded select-none w-full font-bold text-2xl">
Button
</button>
ãã¡ãã¯ã¯ã©ã¹ãè²ã ã¨ããã®ã¯ç¸å¤ãããã ãã æ°ãã«CSSã«ã¯ã©ã¹ãå®ç¾©ãããã¨ã¯ãªãã HTMLã®å¤æ´ã®ã¿ã§çµãã£ãã
ããã§éè¦ãªã®ã¯ãCSSã®ç®¡çãã解æ¾ããã¦ãããã¨ã ã CSSã®ã¦ã¼ã¶ã¼å®ç¾©ãåºã¦ããªãã®ã§ããã è¦ãç®ã®å¤æ´ã¯ã¯ã©ã¹ãä¿®æ£ãã該å½ã®HTMLè¦ç´ ã®ã¿ã§è¡ãããã CSSã¯ã©ã¹ã®ã¹ã¿ã¤ã«ã®ä¿®æ£ãééãã¦ãé¢ä¿ã®ãªãè¦ç´ ã¾ã§å·»ãè¾¼ããã¨ã¯ãªãã å®å ¨ã«è¦ãç®ã®ã«ã¹ã¿ãã¤ãºãå¯è½ãªã®ã ã HTMLã¨CSSã交äºã«è¦ã¦ã«ã¹ã¿ãã¤ãºããå¿ è¦ããªãã
ããã¯ãã£ã¦ããããããåããã¿ã³ä½ããã³ã«ãã®ã¯ã©ã¹ç¾¤ãã³ããããã®ããï¼ ã¨æããããããããªãã ãããªãããã®é¨åã®HTMLãåãåã£ã¦ä½¿ãåããããã«ããã°ããã®ã ã Ruby on Railsãªããã¼ã·ã£ã«ã¨ãã¦åå²ã§ããã ReactãVue.jsãªã©ã®ã³ã³ãã¼ãã³ããã¼ã¹ã®ãã¬ã¼ã ã¯ã¼ã¯ãªãã ãã¿ã³ãã³ã³ãã¼ãã³ãã«ãã¦ãã¾ãã°ããã
ã§ããã£ã±ãç¬èªã®ã³ã³ãã¼ãã³ãã¯ã©ã¹ãä½ããããã¨æããããããªãã å®ã¯Tailwindcssã«ã¯CSSã®ã¹ã¿ã¤ã«å®ç¾©ã«ã¦ã¼ãã£ãªãã£ã¯ã©ã¹ã使ãã¦ãã¾ãã æ®éã«CSSãæ¸ããã楽ã«CSSã®ã¦ã¼ã¶ã¼å®ç¾©ãæ¸ããã®ã ã
.btn {
@apply bg-blue-500 text-white px-4 py-2 rounded select-none;
}
.btn:hover {
@apply bg-blue-600;
}
å½ç¶ã¦ã¼ã¶ã¼å®ç¾©ã®ããååã®è¡çªã¯èµ·ããããã ããããã¦ã¼ãã£ãªãã£ã¯ã©ã¹ã®å½åè¦åããè¦ãã¦ããã°ã ã©ã¤ãã©ãªã®ç¨æããã³ã³ãã¼ãã³ãã¯ã©ã¹ãªãã¦ç¡ãããã å°ãªãã¨ãTailwindcssã®å®ç¾©ããCSSã¨ã®ååè¡çªã¯èµ·ãããªãã ããã
ã¹ã¿ã¤ã«ã®ææ¡ãããã
ã¨ããã§ãBootstrapã®.btn
ã«ã¯ã©ããªã¹ã¿ã¤ã«ãé©å¿ããã¦ããããåç¥ã ãããï¼
.btn {
display: inline-block;
font-weight: 400;
color: #212529;
text-align: center;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: transparent;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
ä½ãè²ã ã¨ã¹ã¿ã¤ã«ããã£ã¦ææ¡ãã¥ããæããã®ã§ã¯ãªãã ãããã ã¾ãããã®ãããã§ããæãã®è¦ãç®ã«ãªã£ã¦ããã®ã ãã
é常ã®CSSãèªã¿è§£ãã«ã¯ã1è¡ãã¤ã¹ã¿ã¤ã«ãè¦ã¦ã æå®ããã¦ããå¤ã¯ä½ã§ãããã§æå®ããã¦ããåä½ã¯ä½ãã ã¨ãããã¨ãææ¡ãã¦ããããé©ç¨ããã¦ããã¹ã¿ã¤ã«ãææ¡ã§ããã
ãã®ã¨ããããã§æå®ããã¦ããå¤ã¨åä½ã®çµã¿åããã§å ·ä½çãªã¹ã¿ã¤ã«ãããã¨ã¤ã¡ã¼ã¸ã§ããã ãããï¼ ããããããã®ãããªæ°å¤ãåä½ã¯ã©ãããåºæºã§æ±ºãããã¦ããã®ã ãããï¼ ãã¬ã¼ã ã¯ã¼ã¯ã®ä½æè ã®æ±ºãããã®ãã¸ãã¯ãã³ãã¼ããç¬èªã®ã«ã¹ã¿ãã¤ãºæã«ã¯ç¡è¦ãã¦ãããã®ã ãããï¼ æåãµã¤ãºãééã®å¤§å°ã¯ã©ãããè¦åã§æ±ºã¾ã£ã¦ããã®ã ãããï¼
ä¸è¦ä½¿ãã®ãç°¡åã«æãããã¬ã¼ã ã¯ã¼ã¯ã§ãã ããæãå ãããã¨æãã¨ããã®ãããªæ··æ²ã«é¥ã£ã¦ãã¾ãã ããã çµæçã«ãè¦ãç®ãã«ã¹ã¿ãã¤ãºããã®ãæããªãã CSSãå«ãã«ãªã£ã¦ãããããããªãã
Tailwindcssã¯ãã®æ··æ²ã解決ããã¢ããã¼ããåã£ã¦ããã
ä»ä¸åº¦Tailwindcssã®ãã¿ã³ã®HTMLãè¦ã¦ã¿ããã
<button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded select-none">
Button
</button>
ãã£ãã®CSSãèªãããã
ããã§æå®ããã¦ããã¯ã©ã¹ç¾¤ãèªãæ¹ãã
ã©ã®ãããªã¹ã¿ã¤ã«ãå½ã¦ããã¦ãããã端çã«ãããã¨æããªãã ãããï¼
ï¼transition
ã®ã¢ãã¡ã¼ã·ã§ã³ãç¡ããã¨ã«ã¯ç®ãã¤ãã£ã¦ããã ãããï¼
Tailwindcssã®ã¦ã¼ãã£ãªãã£ã¯ã©ã¹ã¯ååãè¦ãã°ã©ã®ããã«ã¹ã¿ã¤ã«ãæå®ããã¦ãããä¸ç®çç¶ã§ããã
大æµã®å ´å1ã¤ã®ã¹ã¿ã¤ã«ã®å¤æ´ããããªãã®ã ããå½ç¶ã§ããã
ãã®ãã¨ã§ãåã«btn btn-custom
ãªã©ã®æ½è±¡çãªååã®ã¯ã©ã¹ãæå®ããããããã
HTMLãè¦ãã ãã§å
·ä½çãªç»é¢æ§æã®ã¤ã¡ã¼ã¸ãã¤ãããããªãã
ããã«éè¦ãªç¹æ§ã¨ãã¦ã ã¹ã¿ã¤ã«ã§ä½¿ããå¤ãTailwindcssã«ãã£ã¦éå®ããã¦ããã¨ãããã¨ãæããããã
ä¾ãã°ãTailwindcssã§æåãµã¤ãºãæå®ããå ´åãèãã¦ã¿ããã
Tailwindcssã®font-size
ã«é¢ä¿ããã¯ã©ã¹ãããã¥ã¡ã³ãããè¦ã¦ã¿ããã
.text-xs { font-size: .75rem; }
.text-sm { font-size: .875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem;
.text-4xl { font-size: 2.25rem; }
.text-5xl { font-size: 3rem; }
.text-6xl { font-size: 4rem; }
åä½ã¯rem
ã«çµ±ä¸ãããããããã®ãµã¤ãºã§åç´ã«ãªãã¢ã§ãªãå¤ãæå®ããã¦ããã®ããããã ããã
æåãµã¤ãºã
使ããæåãµã¤ãºãããã§ã«é©åãªæè¦ã§éå®ããã¦ããã®ã ã
ãã®ãã¨ã«ãããã¦ã¼ã¶ã¼ã¯å
·ä½çãªæåãµã¤ãºã®å¤ãåä½ã«é¢ãã¦æ©ã¾ãã«ããã
åç´ã«å°ã大ããæåã使ããããã°text-lg
ãã
ããªãå°ããªæåã使ããããã°text-xs
ã使ãã°ããã®ã ã
è²ãããã£ã³ã°ããã¼ã¸ã³ãªã©ã§ãåæ§ã®ãã¨ã§ã Tailwindcssã®ã¦ã¼ãã£ãªãã£ã¯ã©ã¹ã«ããç¯å²ã§ãé©åãªãã®ãé¸æãã¦ä½¿ãã°ããã ãã®è©±ã«ãªãã ãã§ã«é©åãªé¸æè¢ãç¨æããã¦ããã®ã§ãããããé¸æè¢ããèããå¿ è¦ã¯ãªããªãã®ã ã
CSSã®ç解
Tailwindcssã®ã¡ãªãããè¿°ã¹ã¦ãããã ããã¯ãã£ã¦ãæè©®ã¦ã¼ãã£ãªãã£ã¯ã©ã¹ã®éåã§ããã ãã³ãã¶ã¤ãã¼ã§ãç°¡åã«ããæãã®è¦ãç®ãä½ããã ã¨ãããããªãã¨ã¯Tailwindcssã«ã¯ã§ããªãã
Tailwindcssåä½ã§ããæãã®è¦ãç®ãä½ãã«ã¯ã CSSã®ç解ããã¶ã¤ã³åãUIã®è¨è¨åãå¿ è¦ã«ãªãã ããã ããã«å ãã¦ãã¤ã³ã¿ã©ã¯ãã£ããªUIãä½ãããã¨æã£ããã JavaScript(TypeScript)ã®ç¥èãå¿ è¦ã¨ãªãã
ã§ã¯ããã¶ã¤ã³ãã§ããªãã¨ããç¹å¥CSSã«è©³ãããªããªãTailwindcssã¯ä½¿ãã«å¤ããªãã ãããï¼
ç§ã¯çãã¯ãã¼ã¨æã£ã¦ããã
ãã³ãã¶ã¤ãã¼ã§ãããã¶ã¤ãã¼ã®è¦æéãã«ç»é¢ãä½ãããã¨æã£ããã ãã¯ãCSSã®ç¥èã¯å¿ è¦ã«ãªãã Tailwindcssã使ã£ã¦ããã°ã ææ¡ããããã¦ã¼ãã£ãªãã£ã¯ã©ã¹ãCSS1ã¤1ã¤ã®ã¹ã¿ã¤ã«ã¨1対1ã§å¯¾å¿ãã¦ããã®ã§ã 使ã£ã¦ãããã¡ã«èªç¶ã¨CSSã®ç¥èããCSSåä½ã§å¦ã¶ãã身ã«ã¤ãã¦ããã
ããã¯Bootstrapã§ã³ã³ãã¼ãã³ãã¯ã©ã¹ã®ä½¿ãæ¹ãåå¼·ãã¦ããCSSã®åºç¤çãªç¥èã¯èº«ã«ã¤ããªãã®ã¨å¯¾ç §çã ããã
èªåã ãã§ã¯ããæãã®UIãæãæµ®ãã°ãªãå ´åã§ãã æ¢åã®CSSãã¬ã¼ã ã¯ã¼ã¯ã®ä¾ãçä¼¼ãã¦ã¿ããã åèã«ãªããµã¤ããçä¼¼ãã¦ã¿ãã°è¯ãã ããã ãããã¯ããã£ãã®ãã¨ãã¶ã¤ãã¼ã«ããæãã®ç»é¢ãèãã¦è²°ãã°ããã®ã ã
ãããã¶ã¤ãã¼ã«é ¼ããèªåã ãã§UIãã¾ã¨ãã«è¦ãããã¨æããªãã Tailwindcssã®ä½è ãæ¸ããRefactoring UIãèªããã¨ããªã¹ã¹ã¡ããã UIãé©åã«è¦ããTipsãè±å¯ã«è¼ã£ã¦ããã®ã§ã åèã«ãªããã¨ééããªãã
ã¾ã¨ã
Tailwindcssã¯CSSããã¾ã¨ãã«ãæ¸ããããã«ãªãããã® ãã¼ã«ã ã¨ãããã¨ãããããããã ããã ãããã ããã§ã¯è©³ããã¯è¿°ã¹ãªãããTailwindcssã¯ã¬ã¹ãã³ã·ããªç»é¢ãä½ãã®ãç°¡åã«ã§ããããã«ãªã£ã¦ããã
CSSã¯ã¹ã¿ã¤ã«ã®ä¸æ¸ãã¨ãã¿ã¤ããã¹ããã¦ãå®è¡ã¨ã©ã¼ãåºããªãã¨ãã ä¸å¯è§£ãªåªå é ä½ã§ã¹ã¿ã¤ã«ããã¾ãé©ç¨ãããªãã¨ãã æ§ã ãªã¹ãã¬ã¹ãã¤ãã¾ã¨ããã®ã§ããã Tailwindcssã使ã£ã¦ãã®ã¹ãã¬ã¹ãã解æ¾ããã¦ãèªç±ã«Webã®ç»é¢ãä½ãè¾¼ã楽ãããå³ããããã¨æããªãã ãããï¼
Tailwindcssã«ã¯æ¢è£½åã®ã³ã³ãã¼ãã³ãã¯åå¨ããªãã ããã®ã¯æ®éããã¾ã¨ããªå°ããªé¨åã®éåã ãã ã ããã«ã¯ã1ãããããããã®ãçµã¿ç«ã¦ãåã³ãããã¨ç§ã¯ä¿¡ãããã