HTML & CSS: Struktur – Code-Beispiele
Geordnete und ungeordnete Listen
Anwendungsfall: Aufzählungen, Navigationen und Schrittanleitungen semantisch auszeichnen.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
ul.check { list-style: none; padding-left: 0; }
ul.check li::before { content: "✔ "; color: seagreen; }
ol.schritte li { margin-bottom: 4px; }
ol.schritte li::marker { font-weight: 700; color: #e34f26; }
</style>
<h3>Einkaufsliste</h3>
<ul class="check"><li>Milch</li><li>Brot</li><li>Kaffee</li></ul>
<h3>Anleitung</h3>
<ol class="schritte"><li>Datei anlegen</li><li>HTML schreiben</li><li>Im Browser öffnen</li></ol><ul> für ungeordnete, <ol> für nummerierte Listen mit <li>-Einträgen. Navigationsmenüs sind ebenfalls Listen. Aussehen (Symbole, Zähler) steuerst du mit list-style, ::marker und ::before.
Definitionsliste und Tabelle
Anwendungsfall: Schlüssel-Wert-Daten (Eigenschaften, Preislisten, Steckbriefe) verständlich darstellen.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
dt { font-weight: 700; } dd { margin: 0; }
table { border-collapse: collapse; margin-top: 12px; }
th, td { border: 1px solid #bbb; padding: 4px 12px; text-align: left; }
th { background: #eee; }
</style>
<dl><dt>Name</dt><dd>Ada Lovelace</dd><dt>Beruf</dt><dd>Mathematikerin</dd></dl>
<table>
<tr><th>Land</th><th>Hauptstadt</th></tr>
<tr><td>DE</td><td>Berlin</td></tr>
<tr><td>FR</td><td>Paris</td></tr>
</table>Das Gegenstück zu einer Map: <dl> mit <dt> (Schlüssel) und <dd> (Wert) für einzelne Zuordnungen, <table> für mehrere Datensätze mit gleichen Spalten (wie eine Liste von Maps).
Tabelle mit Zebra-Streifen
Struktur#table#nth-child#zebra
Anwendungsfall: Datenlisten wie Bestellungen oder Rankings gut lesbar darstellen.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
table { border-collapse: collapse; width: 100%; max-width: 460px; }
caption { text-align: left; font-weight: 700; padding: 6px 0; }
th, td { padding: 8px 12px; text-align: left; }
thead th { background: #1f2937; color: #fff; }
tbody tr:nth-child(even) { background: #f3f4f6; }
tbody tr:hover { background: #e0e7ff; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
</style>
<table>
<caption>Umsatz nach Kunde</caption>
<thead><tr><th scope="col">Kunde</th><th scope="col" class="zahl">Umsatz</th></tr></thead>
<tbody>
<tr><th scope="row">Ada</th><td class="zahl">1.138,00 €</td></tr>
<tr><th scope="row">Dana</th><td class="zahl">1.089,00 €</td></tr>
<tr><th scope="row">Ben</th><td class="zahl">85,00 €</td></tr>
</tbody>
</table>caption, thead/tbody und th scope machen die Tabelle zugänglich. :nth-child(even) liefert Streifen, tabular-nums richtet Ziffern aus, Zahlen stehen rechtsbündig.