{
"$schema": "../schemas/code-crispies-module-schema.json",
"id": "selectors",
"title": "Specificity",
"description": "Master the art of targeting HTML elements using various CSS selectors, from basics to specificity rules.",
"difficulty": "beginner",
"lessons": [
{
"id": "selectors-1",
"title": "Element Selectors",
"description": "Learn to target HTML elements by their tag name and apply styling.",
"task": "Use the element selector to make all <p> tags have a dark gray color.",
"previewHTML": "
This paragraph should be dark gray.
This one too!
", "previewBaseCSS": "body { font-family: sans-serif; padding: 1rem; }", "sandboxCSS": "", "codePrefix": "/* Style all paragraphs */\n", "initialCode": "", "codeSuffix": "", "previewContainer": "preview-area", "concept": { "explanation": "Element selectors work by matching the tag name against every node in the DOM tree. The browser traverses the entire document, checking each element's type. When it finds a match, it applies the styles. This is why p selects ALL paragraph elements—the browser doesn't stop after the first match. Element selectors have the lowest specificity (0,0,0,1), making them easy to override with classes or IDs.", "diagram": "Browser DOM Traversal\n\n\n \n? NO\n
← Check: is this a
? YES ✓ Apply styles\n
? NO\n
← Check: is this a
? YES ✓ Apply styles\n \n\n\nSpecificity: 0,0,0,1 (lowest)" }, "validations": [ { "type": "contains", "value": "p {", "message": "Use the element selector p", "options": { "caseSensitive": false } }, { "type": "contains", "value": "color", "message": "Include the color property", "options": { "caseSensitive": false } }, { "type": "property_value", "value": { "property": "color", "expected": "darkgray" }, "message": "Set color to darkgray", "options": { "exact": false } } ] }, { "id": "selectors-2", "title": "Class Selectors", "description": "Use class selectors to style elements sharing the same class name.", "task": "Apply a blueviolet text color to any element with the class 'title'.", "previewHTML": "
id=\"description\" have orangered text.",
"previewHTML": "div.note) to give a yellow background to the note box.",
"previewHTML": "✗ wrong element type\n