|
1 | 1 | { |
2 | 2 | "$schema": "../schemas/code-crispies-module-schema.json", |
3 | 3 | "id": "tailwind-basics", |
4 | | - "title": "Tailwind CSS Basics", |
| 4 | + "title": "Tailwind CSS Basics - Understanding Utility-First Design", |
| 5 | + "description": "Learn how Tailwind CSS revolutionizes styling by replacing traditional CSS selectors with utility-first classes. Understand the philosophy behind utility classes and how they solve common CSS problems like specificity conflicts and maintenance complexity.", |
5 | 6 | "mode": "tailwind", |
| 7 | + "difficulty": "beginner", |
6 | 8 | "lessons": [ |
7 | 9 | { |
8 | 10 | "id": "bg-colors", |
|
11 | 13 | "task": "Add a blue background to the div using Tailwind classes.", |
12 | 14 | "previewHTML": "<div class=\"{{USER_CLASSES}} p-8 rounded\">Hello Tailwind!</div>", |
13 | 15 | "previewBaseCSS": "body { padding: 20px; font-family: sans-serif; }", |
| 16 | + "sandboxCSS": "", |
14 | 17 | "initialCode": "", |
| 18 | + "previewContainer": "preview-area", |
15 | 19 | "validations": [ |
16 | 20 | { |
17 | 21 | "type": "contains_class", |
18 | 22 | "value": "bg-blue-500", |
19 | 23 | "message": "Add the 'bg-blue-500' class for a blue background." |
20 | 24 | } |
21 | | - ], |
22 | | - "sandboxCSS": "", |
23 | | - "previewContainer": "" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "id": "utility-first-philosophy", |
| 29 | + "title": "Understanding Utility-First Design", |
| 30 | + "description": "Tailwind CSS follows a utility-first approach where instead of writing custom CSS classes, you compose designs using small, single-purpose utility classes. Unlike traditional CSS where you might write <kbd>.card { background: white; padding: 1rem; border-radius: 0.5rem; }</kbd>, Tailwind provides pre-built utilities like <kbd>bg-white</kbd>, <kbd>p-4</kbd>, and <kbd>rounded</kbd>.<br><br>The <kbd>bg-white</kbd> utility sets <kbd>background-color: white</kbd>, <kbd>p-4</kbd> applies <kbd>padding: 1rem</kbd> on all sides, and <kbd>rounded</kbd> adds <kbd>border-radius: 0.25rem</kbd>. This approach eliminates the need to context-switch between HTML and CSS files.", |
| 31 | + "task": "Create a white card-like container with a small drop-shadow, 1rem padding and rounded corners.", |
| 32 | + "previewHTML": "<div class=\"bg-gray-100 p-6\">\n <div class=\"{{USER_CLASSES}}\">\n <h3 class=\"text-lg font-semibold mb-2\">Card Title</h3>\n <p class=\"text-gray-600\">This is a card component built entirely with utility classes!</p>\n </div>\n</div>", |
| 33 | + "previewBaseCSS": "body { font-family: sans-serif; margin: 0; }", |
| 34 | + "sandboxCSS": "/* Traditional CSS approach:\n.card {\n background-color: white;\n padding: 1rem;\n border-radius: 0.25rem;\n}\n*/", |
| 35 | + "initialCode": "", |
| 36 | + "previewContainer": "preview-area", |
| 37 | + "validations": [ |
| 38 | + { |
| 39 | + "type": "contains_class", |
| 40 | + "value": "bg-white", |
| 41 | + "message": "Add <kbd>bg-white</kbd> to set the background color to white." |
| 42 | + }, |
| 43 | + { |
| 44 | + "type": "contains_class", |
| 45 | + "value": "p-4", |
| 46 | + "message": "Add <kbd>p-4</kbd> to apply 1rem padding on all sides." |
| 47 | + }, |
| 48 | + { |
| 49 | + "type": "contains_class", |
| 50 | + "value": "rounded", |
| 51 | + "message": "Add <kbd>rounded</kbd> to apply border-radius of 0.25rem." |
| 52 | + }, |
| 53 | + { |
| 54 | + "type": "contains_class", |
| 55 | + "value": "shadow-sm", |
| 56 | + "message": "Add <kbd>shadow-sm</kbd> to apply small drop-shadow." |
| 57 | + } |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "id": "text-utilities", |
| 62 | + "title": "Text Color and Size Utilities", |
| 63 | + "description": "Tailwind provides comprehensive text utilities for styling typography. Text colors use the pattern <kbd>text-{color}-{shade}</kbd> where colors include red, blue, green, etc., and shades range from 50 (lightest) to 950 (darkest). For example, <kbd>text-blue-600</kbd> applies a medium blue color.<br><br>Text sizes follow the pattern <kbd>text-{size}</kbd> with options like <kbd>text-sm</kbd> (0.875rem), <kbd>text-base</kbd> (1rem), <kbd>text-lg</kbd> (1.125rem), <kbd>text-xl</kbd> (1.25rem), and larger sizes up to <kbd>text-9xl</kbd>. Font weights use <kbd>font-{weight}</kbd> such as <kbd>font-normal</kbd>, <kbd>font-medium</kbd>, <kbd>font-semibold</kbd>, and <kbd>font-bold</kbd>.", |
| 64 | + "task": "Style the heading with <kbd>text-blue-600</kbd> for color, <kbd>text-2xl</kbd> for size, and <kbd>font-bold</kbd> for weight.", |
| 65 | + "previewHTML": "<div class=\"p-6 bg-gray-50\">\n <h1 class=\"{{USER_CLASSES}} mb-4\">Welcome to Tailwind CSS</h1>\n <p class=\"text-gray-700\">This heading demonstrates text utilities in action.</p>\n</div>", |
| 66 | + "previewBaseCSS": "body { font-family: sans-serif; margin: 0; }", |
| 67 | + "sandboxCSS": "/* Traditional CSS would be:\nh1 {\n color: #2563eb;\n font-size: 1.5rem;\n font-weight: 700;\n}\n*/", |
| 68 | + "initialCode": "", |
| 69 | + "previewContainer": "preview-area", |
| 70 | + "validations": [ |
| 71 | + { |
| 72 | + "type": "contains_class", |
| 73 | + "value": "text-blue-600", |
| 74 | + "message": "Add <kbd>text-blue-600</kbd> to make the text blue" |
| 75 | + }, |
| 76 | + { |
| 77 | + "type": "contains_class", |
| 78 | + "value": "text-2xl", |
| 79 | + "message": "Add <kbd>text-2xl</kbd> to increase the font size to 1.5rem" |
| 80 | + }, |
| 81 | + { |
| 82 | + "type": "contains_class", |
| 83 | + "value": "font-bold", |
| 84 | + "message": "Add <kbd>font-bold</kbd> to make the text bold (font-weight: 700)" |
| 85 | + } |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "id": "spacing-utilities", |
| 90 | + "title": "Spacing with Padding and Margin", |
| 91 | + "description": "Tailwind's spacing utilities follow a consistent pattern using a spacing scale where each unit represents 0.25rem (4px). Padding utilities use <kbd>p-{size}</kbd> for all sides, <kbd>px-{size}</kbd> for horizontal (left/right), <kbd>py-{size}</kbd> for vertical (top/bottom), or individual sides like <kbd>pt-{size}</kbd>, <kbd>pr-{size}</kbd>, <kbd>pb-{size}</kbd>, <kbd>pl-{size}</kbd>.<br><br>Common sizes include <kbd>p-2</kbd> (0.5rem), <kbd>p-4</kbd> (1rem), <kbd>p-6</kbd> (1.5rem), and <kbd>p-8</kbd> (2rem). Margin follows the same pattern but uses <kbd>m-</kbd> instead of <kbd>p-</kbd>. For example, <kbd>mx-auto</kbd> centers an element horizontally by applying automatic left and right margins.", |
| 92 | + "task": "Style the button with <kbd>px-6</kbd> for horizontal padding, <kbd>py-3</kbd> for vertical padding, and <kbd>mx-auto</kbd> to center it.", |
| 93 | + "previewHTML": "<div class=\"p-6 bg-gray-100\">\n <button class=\"{{USER_CLASSES}} bg-blue-500 text-white rounded block\">\n Centered Button\n </button>\n</div>", |
| 94 | + "previewBaseCSS": "body { font-family: sans-serif; margin: 0; }", |
| 95 | + "sandboxCSS": "/* Traditional CSS equivalent:\nbutton {\n padding-left: 1.5rem;\n padding-right: 1.5rem;\n padding-top: 0.75rem;\n padding-bottom: 0.75rem;\n margin-left: auto;\n margin-right: auto;\n}\n*/", |
| 96 | + "initialCode": "", |
| 97 | + "previewContainer": "preview-area", |
| 98 | + "validations": [ |
| 99 | + { |
| 100 | + "type": "contains_class", |
| 101 | + "value": "px-6", |
| 102 | + "message": "Add <kbd>px-6</kbd> for horizontal padding (1.5rem left and right)" |
| 103 | + }, |
| 104 | + { |
| 105 | + "type": "contains_class", |
| 106 | + "value": "py-3", |
| 107 | + "message": "Add <kbd>py-3</kbd> for vertical padding (0.75rem top and bottom)" |
| 108 | + }, |
| 109 | + { |
| 110 | + "type": "contains_class", |
| 111 | + "value": "mx-auto", |
| 112 | + "message": "Add <kbd>mx-auto</kbd> to center the button horizontally" |
| 113 | + } |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "id": "responsive-design", |
| 118 | + "title": "Responsive Design with Breakpoint Prefixes", |
| 119 | + "description": "Tailwind uses a mobile-first responsive design approach with breakpoint prefixes. The base utilities apply to all screen sizes, then you add prefixes for larger screens: <kbd>sm:</kbd> (640px+), <kbd>md:</kbd> (768px+), <kbd>lg:</kbd> (1024px+), <kbd>xl:</kbd> (1280px+), and <kbd>2xl:</kbd> (1536px+).<br><br>For example, <kbd>text-base md:text-lg lg:text-xl</kbd> makes text normal size on mobile, larger on tablets (md), and even larger on desktop (lg). Each breakpoint overrides the previous one, so <kbd>p-4 md:p-6 lg:p-8</kbd> means 1rem padding on mobile, 1.5rem on tablets, and 2rem on desktop.<br><br>Width utilities like <kbd>w-full</kbd> (100% width), <kbd>w-1/2</kbd> (50% width), or fixed sizes like <kbd>w-64</kbd> (16rem) can also be made responsive.", |
| 120 | + "task": "Make the box responsive: <kbd>w-full</kbd> on mobile, <kbd>md:w-1/2</kbd> on tablets, and <kbd>lg:w-1/3</kbd> on desktop. Also add responsive text sizing with <kbd>text-lg</kbd>, <kbd>md:text-xl</kbd>, and <kbd>lg:text-2xl</kbd>.", |
| 121 | + "previewHTML": "<div class=\"p-6 bg-gray-100\">\n <div class=\"{{USER_CLASSES}} bg-purple-500 text-white p-6 rounded text-center\">\n <span>Responsive Box</span><br>\n <small class=\"opacity-75\">Resize your browser to see the effect!</small>\n </div>\n</div>", |
| 122 | + "previewBaseCSS": "body { font-family: sans-serif; margin: 0; }", |
| 123 | + "sandboxCSS": "/* Traditional CSS would require media queries:\n.responsive-box {\n width: 100%;\n font-size: 1.125rem;\n}\n@media (min-width: 768px) {\n .responsive-box {\n width: 50%;\n font-size: 1.25rem;\n }\n}\n@media (min-width: 1024px) {\n .responsive-box {\n width: 33.333333%;\n font-size: 1.5rem;\n }\n}\n*/", |
| 124 | + "initialCode": "", |
| 125 | + "previewContainer": "preview-area", |
| 126 | + "validations": [ |
| 127 | + { |
| 128 | + "type": "contains_class", |
| 129 | + "value": "w-full", |
| 130 | + "message": "Add <kbd>w-full</kbd> for 100% width on mobile" |
| 131 | + }, |
| 132 | + { |
| 133 | + "type": "contains_class", |
| 134 | + "value": "md:w-1/2", |
| 135 | + "message": "Add <kbd>md:w-1/2</kbd> for 50% width on tablet and up" |
| 136 | + }, |
| 137 | + { |
| 138 | + "type": "contains_class", |
| 139 | + "value": "lg:w-1/3", |
| 140 | + "message": "Add <kbd>lg:w-1/3</kbd> for 33.33% width on desktop and up" |
| 141 | + }, |
| 142 | + { |
| 143 | + "type": "contains_class", |
| 144 | + "value": "text-lg", |
| 145 | + "message": "Add <kbd>text-lg</kbd> for the base text size" |
| 146 | + }, |
| 147 | + { |
| 148 | + "type": "contains_class", |
| 149 | + "value": "md:text-xl", |
| 150 | + "message": "Add <kbd>md:text-xl</kbd> for larger text on tablets" |
| 151 | + }, |
| 152 | + { |
| 153 | + "type": "contains_class", |
| 154 | + "value": "lg:text-2xl", |
| 155 | + "message": "Add <kbd>lg:text-2xl</kbd> for even larger text on desktop" |
| 156 | + } |
| 157 | + ] |
24 | 158 | } |
25 | | - ], |
26 | | - "description": "", |
27 | | - "difficulty": "advanced" |
| 159 | + ] |
28 | 160 | } |
0 commit comments