Sidebar + Content Layout
Teil des Abschnitts Practical Frontend der HTML-Journey von Coddy — Lektion 28 von 35.
Das Sidebar + Content-Layout ist ein gängiges responsives Muster, bei dem Sie einen Hauptinhaltsbereich und eine Seitenleiste für die Navigation oder zusätzliche Informationen haben.
Beginnen Sie mit der grundlegenden HTML-Struktur:
<div class="container">
<main class="content">Main content here</main>
<aside class="sidebar">Sidebar content here</aside>
</div>Fügen Sie nun das CSS für einen Mobile-First-Ansatz hinzu:
.container {
display: flex;
flex-direction: column;
max-width: 1200px;
margin: 0 auto;
}
.content {
padding: 20px;
}
.sidebar {
padding: 20px;
background-color: #f5f5f5;
}Fügen Sie dann eine Media-Query hinzu, um auf größeren Bildschirmen ein Nebeneinander-Layout zu erstellen:
@media (min-width: 768px) {
.container {
flex-direction: row;
}
.content {
flex: 3;
}
.sidebar {
flex: 1;
}
}Dies erstellt ein responsives Layout, das auf Mobilgeräten untereinander gestapelt wird und auf größeren Bildschirmen nebeneinander erscheint.
Aufgabe
EinfachSie erhalten ein responsives Sidebar + Content Layout, das nach dem Mobile-First-Ansatz gestaltet ist.
Ihre Aufgabe:
- Lassen Sie die Sidebar auf Bildschirmen, die breiter als 768px sind, auf der rechten Seite des Inhalts erscheinen.
- Geben Sie auf größeren Bildschirmen dem Inhaltsbereich 70% width und der Sidebar 30% width.
Spickzettel
Das Sidebar + Content Layout verwendet Flexbox, um ein responsives Muster mit einem Hauptinhaltsbereich und einer Seitenleiste zu erstellen.
Grundlegende HTML-Struktur:
<div class="container">
<main class="content">Main content here</main>
<aside class="sidebar">Sidebar content here</aside>
</div>Mobile-First-CSS-Ansatz:
.container {
display: flex;
flex-direction: column;
max-width: 1200px;
margin: 0 auto;
}
.content {
padding: 20px;
}
.sidebar {
padding: 20px;
background-color: #f5f5f5;
}Media-Query für größere Bildschirme:
@media (min-width: 768px) {
.container {
flex-direction: row;
}
.content {
flex: 3;
}
.sidebar {
flex: 1;
}
}Dies erstellt ein Layout, das auf Mobilgeräten vertikal gestapelt wird und auf größeren Bildschirmen nebeneinander angezeigt wird.
Probier es selbst
<!DOCTYPE html>
<html>
<head>
<title>Sidebar + Content Layout</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Segoe UI", Arial, sans-serif;
line-height: 1.6;
background: #f5f7fa;
color: #333;
}
.container {
display: flex;
flex-direction: column;
max-width: 1100px;
margin: 40px auto;
background: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.content {
padding: 25px;
}
.content h2 {
color: #2a6592;
margin-bottom: 15px;
}
.content p {
margin-bottom: 1em;
}
.sidebar {
padding: 25px;
background-color: #eaf3fa;
border-left: 3px solid #2a6592;
}
.sidebar h3 {
margin-bottom: 15px;
color: #2a6592;
}
.sidebar ul {
list-style: none;
padding-left: 0;
}
.sidebar li {
margin: 10px 0;
}
.sidebar a {
text-decoration: none;
color: #2a6592;
font-weight: 500;
transition: color 0.2s;
}
.sidebar a:hover {
color: #17405d;
}
@media (min-width: 768px) {
}
</style>
</head>
<body>
<div class="container">
<main class="content">
<h2>Exploring Italy: A Travel Story</h2>
<p>Italy is a country full of culture, history, and delicious food. From the romantic canals of Venice to the ancient ruins of Rome, every corner tells a story.</p>
<p>During my trip, I explored Florence’s Renaissance art, enjoyed authentic pizza in Naples, and relaxed on the beautiful Amalfi Coast. Each city offered something unique and unforgettable.</p>
<p>If you’re planning a trip, I recommend taking the time to explore both big cities and small villages. You’ll find hidden gems, welcoming locals, and memories that last forever.</p>
</main>
<aside class="sidebar">
<h3>More Travel Guides</h3>
<ul>
<li><a href="#">Top 10 Things to Do in Rome</a></li>
<li><a href="#">A Foodie’s Guide to Naples</a></li>
<li><a href="#">Venice on a Budget</a></li>
<li><a href="#">Best Beaches of Amalfi Coast</a></li>
</ul>
</aside>
</div>
</body>
</html>
Diese Lektion enthält ein kurzes Quiz. Starte die Lektion, um es zu beantworten und deinen Fortschritt zu speichern.
Alle Lektionen in Practical Frontend
1Variablen
VariablenCSS-Variablen verwendenVariablen für Design TokensLokale VariablenWiederholungs-Challenge7Abschlussherausforderungen
ProfilkarteSchokoladengalerie-RasterSieben WeltwunderNeue sieben Weltwunder3Theming & Visuelle Stile
Theming in CSSDark/Light Mode GrundlagenAkzentfarben & HervorhebungTypografie-ThemingRecap-Challenge6Responsive Muster
Holy-Grail-LayoutCard-Grid-LayoutSidebar + Content LayoutSplit-Screen-LayoutSticky Header / FooterRecap-Challenge