{ "$schema": "../../schemas/code-crispies-module-schema.json", "id": "html-data-attributes", "title": "Benutzerdefinierte Data-Attribute", "description": "Speichere eigene Daten auf HTML-Elementen mit data-* Attributen", "mode": "html", "difficulty": "beginner", "lessons": [ { "id": "data-attributes-intro", "title": "Data-Attribute hinzufügen", "description": "Benutzerdefinierte data-*-Attribute ermöglichen es, zusätzliche Informationen auf jedem HTML-Element zu speichern. Der Attributname beginnt mit data- gefolgt von deinem eigenen Namen.

Beispiele: data-id, data-category, data-price", "task": "Erstelle zwei Produkt-Karten mit <article>-Elementen. Jede sollte haben:
1. Ein data-category-Attribut (z.B. 'electronics' oder 'clothing')
2. Ein data-price-Attribut mit einer Zahl
3. Ein <h2> mit dem Produktnamen", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; display: grid; gap: 15px; } article { padding: 20px; border-radius: 10px; background: #f5f5f5; border-left: 4px solid #ccc; } article[data-category='electronics'] { border-left-color: #2196f3; background: #e3f2fd; } article[data-category='clothing'] { border-left-color: #e91e63; background: #fce4ec; } h2 { margin: 0 0 10px 0; } article::after { content: '€' attr(data-price); display: block; font-weight: bold; color: #4caf50; margin-top: 10px; }", "sandboxCSS": "", "initialCode": "", "solution": "
\n

Laptop

\n

Ein leistungsstarker Laptop für Arbeit und Freizeit.

\n
\n\n
\n

T-Shirt

\n

Ein bequemes Baumwoll-T-Shirt.

\n
", "previewContainer": "preview-area", "validations": [ { "type": "element_count", "value": { "selector": "article[data-category]", "min": 2 }, "message": "Erstelle mindestens 2 Articles mit data-category-Attributen" }, { "type": "element_count", "value": { "selector": "article[data-price]", "min": 2 }, "message": "Füge data-price-Attribute zu deinen Articles hinzu" }, { "type": "element_count", "value": { "selector": "article h2", "min": 2 }, "message": "Füge ein <h2> in jeden Article ein" } ] }, { "id": "data-attributes-css", "title": "Styling mit Data-Attributen", "description": "CSS kann Elemente über ihre Data-Attribute mit [data-*]-Selektoren auswählen. Du kannst sogar bestimmte Werte abgleichen!

Das Vorschau-CSS verwendet [data-status='active'], um aktive Elemente anders zu stylen.", "task": "Erstelle eine Aufgabenliste mit 3 <li>-Elementen. Gib jedem ein data-status-Attribut:
1. Eines mit data-status=\"completed\"
2. Eines mit data-status=\"active\"
3. Eines mit data-status=\"pending\"", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } ul { list-style: none; padding: 0; } li { padding: 15px; margin: 8px 0; border-radius: 8px; background: #f5f5f5; } li[data-status='completed'] { background: #c8e6c9; text-decoration: line-through; color: #388e3c; } li[data-status='active'] { background: #fff3e0; border-left: 4px solid #ff9800; font-weight: 600; } li[data-status='pending'] { background: #e3f2fd; color: #1976d2; }", "sandboxCSS": "", "initialCode": "", "solution": "", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "li[data-status='completed']", "message": "Füge ein Element mit data-status=\"completed\" hinzu" }, { "type": "element_exists", "value": "li[data-status='active']", "message": "Füge ein Element mit data-status=\"active\" hinzu" }, { "type": "element_exists", "value": "li[data-status='pending']", "message": "Füge ein Element mit data-status=\"pending\" hinzu" } ] } ] }