Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| de:modul:m291:learningunits:lu02:theorie:a_css-intro [2026/02/01 21:51] – angelegt gkoch | de:modul:m291:learningunits:lu02:theorie:a_css-intro [2026/02/02 01:29] (aktuell) – gkoch | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== | + | ====== |
| - | Was heisst Kaskade etc. | + | |
| + | <WRAP center round box 80%> | ||
| + | **Ziel von LU02:** Sie bringen Ihr Projekt „Landingpage Alarado“ optisch näher ans Figma-Design, | ||
| + | \\ | ||
| + | - die Schrift (Google Font) einbinden, | ||
| + | - Designwerte als CSS-Variablen definieren und | ||
| + | - mit Media Queries das Responsive-Layout für Mobile umsetzen. | ||
| + | </ | ||
| + | ==== Lernziele ==== | ||
| + | * Sie können eine Google Font per ''< | ||
| + | * Sie verstehen '' | ||
| + | * Sie können CSS-Variablen in '': | ||
| + | * Sie verstehen die CSS-**Kaskade** (Vererbung, Spezifität, | ||
| + | * Sie können Media Queries für Responsive Design nutzen und mit DevTools testen. | ||
| + | ---- | ||
| + | |||
| + | ===== 1) Fonts im Web ===== | ||
| + | {{: | ||
| + | |||
| + | ==== Google Fonts via CDN ==== | ||
| + | In vielen Projekten werden Fonts schnell über ein CDN eingebunden (z.B. Google Fonts). Das ist praktisch für Schulprojekte und schnelle Prototypen. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Typischer Aufbau im ''< | ||
| + | <code html> | ||
| + | <link rel=" | ||
| + | <link rel=" | ||
| + | <link | ||
| + | href=" | ||
| + | rel=" | ||
| + | /> | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Dann im CSS verwenden: | ||
| + | <code css> | ||
| + | body { | ||
| + | font-family: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <WRAP center round tip 70%> | ||
| + | **Praxis-Hinweis: | ||
| + | </ | ||
| + | |||
| + | ==== Fonts lokal speichern ==== | ||
| + | Wenn Fonts lokal im Projekt liegen, werden sie mit '' | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | @font-face { | ||
| + | font-family: | ||
| + | src: url(" | ||
| + | font-weight: | ||
| + | font-style: normal; | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ((Für lokale Fonts brauchen Sie die Font-Dateien im Projekt, idealerweise '' | ||
| + | |||
| + | ==== Wichtige Font-Eigenschaften ==== | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Einheiten bei Schriftgroessen ==== | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Wichtig: | ||
| + | \\ | ||
| + | Viele Menschen nutzen Browser-Zoom oder haben eine grössere Standard-Schrift eingestellt. | ||
| + | </ | ||
| + | |||
| + | === px === | ||
| + | * '' | ||
| + | * Vorteil: direkt und einfach. | ||
| + | * Nachteil: In grossen Projekten wird es schnell unübersichtlich, | ||
| + | |||
| + | ((Browser-Zoom vergrössert zwar alles. Trotzdem ist '' | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | h1 { font-size: 64px; } | ||
| + | p { font-size: 18px; } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | === em === | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ((Historisch stammt „em“ aus der Typografie. In CSS ist '' | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | body { font-size: 16px; } /* Basis */ | ||
| + | h1 { font-size: 2em; } /* 2 × 16px = 32px */ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | **Die typische EM-Falle** | ||
| + | Wenn mehrere Eltern-Elemente die Schrift bereits verändern, multipliziert sich der Effekt: | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | body { font-size: 1.2em; } /* 1.2 × 16px = 19.2px */ | ||
| + | div { font-size: 1.3em; } /* 1.3 × 19.2px = 24.96px */ | ||
| + | h1 { font-size: 2em; } /* 2 × 24.96px = 49.92px */ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ((Darum ist '' | ||
| + | |||
| + | **Wann ist em sinnvoll** | ||
| + | * Für Proportionen innerhalb einer Komponente: Padding, Icon-Grössen, | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | button { | ||
| + | font-size: 1rem; | ||
| + | padding: 0.8em 1.2em; /* wächst mit der Button-Schrift */ | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | === rem === | ||
| + | * '' | ||
| + | * Vorteil: bleibt konsistent, egal wie tief ein Element verschachtelt ist. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | html { font-size: 16px; } | ||
| + | h1 { font-size: 4rem; } /* 64px */ | ||
| + | p { font-size: 1.125rem; } /* 18px */ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ((Mit '' | ||
| + | |||
| + | ==== Empfehlung für dieses Modul ==== | ||
| + | * Für Schriftgroessen überwiegend **rem** verwenden. | ||
| + | * **em** gezielt innerhalb von Komponenten einsetzen. | ||
| + | * **px** sparsam einsetzen, z.B. für 1px Linien oder sehr feine Details. | ||
| + | |||
| + | ==== line-height ==== | ||
| + | Setzen Sie '' | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | body { line-height: | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ((Einheitenlose '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 2) CSS-Variablen ===== | ||
| + | |||
| + | ==== Was sind CSS-Variablen ==== | ||
| + | CSS-Variablen sind benannte Werte, die Sie einmal zentral definieren und dann überall wiederverwenden. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | :root { | ||
| + | --primary: #263fa9; | ||
| + | --text: #223344; | ||
| + | --h1-size: 4rem; | ||
| + | } | ||
| + | |||
| + | body { color: var(--text); | ||
| + | button { background: var(--primary); | ||
| + | h1 { font-size: var(--h1-size); | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== Warum lohnt sich das ==== | ||
| + | * **Wiederverwendbarkeit: | ||
| + | * **Wartbarkeit: | ||
| + | * **Lesbarkeit: | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Vergleich zu Print-Design** | ||
| + | \\ | ||
| + | CSS-Variablen funktionieren ähnlich wie Absatz- und Zeichenstile: | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 3) CSS Cascade ===== | ||
| + | {{: | ||
| + | \\ | ||
| + | //Viele CSS-Regeln funktionieren nach dem Prinzip " | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Was ist die Kaskade** | ||
| + | \\ | ||
| + | Die CSS-Kaskade entscheidet, | ||
| + | </ | ||
| + | |||
| + | ==== Vererbung ==== | ||
| + | Einige Eigenschaften werden von Eltern an Kinder **vererbt**. | ||
| + | |||
| + | * Häufig vererbt: '' | ||
| + | * Meist nicht vererbt: '' | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | body { | ||
| + | font-family: | ||
| + | color: #223344; | ||
| + | line-height: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== Überschreiben ==== | ||
| + | Wenn zwei Regeln dieselbe Eigenschaft setzen, gilt diese Reihenfolge: | ||
| + | |||
| + | - **Wichtigkeit: | ||
| + | - **Spezifität: | ||
| + | - **Reihenfolge: | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | a { color: black; } | ||
| + | .menu a { color: gray; } | ||
| + | a.active { color: blue; } | ||
| + | #special a { color: red; } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== Reihenfolge im CSS ==== | ||
| + | Bei gleicher Spezifität gewinnt die Regel, die später im CSS steht. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | .menu a { color: gray; } | ||
| + | .menu a { color: green; } /* gewinnt, weil später */ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Für ein vertieftes Verständnis schauen Sie sich diese interaktive Darstellung an: | ||
| + | [[https:// | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 4) Media Queries und Responsive Design ===== | ||
| + | {{: | ||
| + | |||
| + | ==== Was macht eine Media Query ==== | ||
| + | Media Queries passen die Darstellung an verschiedene Bildschirmbreiten an. Der Inhalt bleibt gleich, nur das Layout ändert sich. | ||
| + | |||
| + | ==== Breakpoints ==== | ||
| + | Ein Breakpoint ist eine Breite, bei der Sie das Layout anpassen, weil es sonst nicht mehr sauber wirkt. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | @media (width < 1024px) { ... } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Typische Hinweise, dass ein Breakpoint nötig ist: | ||
| + | * Elemente überlappen oder stossen sich | ||
| + | * Navigation passt nicht mehr | ||
| + | * 2 Spalten werden zu eng | ||
| + | * horizontales Scrollen entsteht | ||
| + | |||
| + | <WRAP center round tip 70%> | ||
| + | **Merksatz: | ||
| + | </ | ||
| + | |||
| + | ==== Beispiel aus unserem Projekt ==== | ||
| + | Desktop: Text links, Bild rechts. | ||
| + | Mobile: Bild oben, Text darunter. | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | <code css> | ||
| + | # | ||
| + | |||
| + | @media screen and (width < 1024px) { | ||
| + | # | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== Media Queries und Kaskade ==== | ||
| + | Media Queries folgen denselben Regeln wie normales CSS: | ||
| + | * Bei aktivem Breakpoint überschreiben Sie nur die Eigenschaften, | ||
| + | * Bei gleicher Spezifität gewinnt die Regel, die später kommt. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 5) Responsive Testing mit DevTools ===== | ||
| + | {{: | ||
| + | |||
| + | * Öffnen Sie DevTools (Chrome/ | ||
| + | * Aktivieren Sie Device Toolbar (Handy/ | ||
| + | * Testen Sie: | ||
| + | - Breitenwechsel über/unter 1024px | ||
| + | - Presets (z.B. iPhone, iPad) | ||
| + | - Hoch-/ | ||
| + | * Prüfen Sie: | ||
| + | - Überlappungen oder abgeschnittene Bereiche | ||
| + | - horizontales Scrollen | ||
| + | - Lesbarkeit der Schrift | ||
| + | |||
| + | <WRAP center round box 80%> | ||
| + | **Praxis-Tipp** | ||
| + | \\ | ||
| + | Wenn etwas nicht greift: DevTools → „Styles“ öffnen und schauen, welche Regel durchgestrichen ist. Das ist Kaskade in Aktion. | ||
| + | </ | ||