On this page10 sections
Lecture 032: Website Layout
| Category | 6: CSS in Depth |
| Lecture | 032 of 057 |
| Estimated video length | 14 min |
| Target | CSS3 · any modern browser |
| Level | Intermediate |
Most websites share one skeleton: a header, a navigation bar, the content (often with a sidebar), and a footer. This lecture builds that whole layout step by step, responsive from phone to desktop.
Learning Objectives
- Plan a page layout from its parts
- Build it with semantic HTML and CSS Grid
- Make it switch from one column on phones to several on desktops
- Keep the footer at the bottom of short pages
1. The Parts
+-------------------------------+
| header |
+-------------------------------+
| nav |
+--------+----------------------+
| | |
| aside | main |
| | |
+--------+----------------------+
| footer |
+-------------------------------+2. The HTML
<header>…</header>
<nav>…</nav>
<div class="layout">
<aside>…</aside>
<main>…</main>
</div>
<footer>…</footer>3. The Complete Page
Example: drag the preview corner from wide to narrow:
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; color: #212529; min-height: 100vh;
display: grid; grid-template-rows: auto auto 1fr auto; }
header { background: #364fc7; color: white; padding: 20px; text-align: center; }
header h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); }
nav { background: #212529; display: flex; flex-wrap: wrap; }
nav a { color: #e9ecef; padding: 12px 16px; text-decoration: none; }
nav a:hover { background: #343a40; }
.layout { display: grid; gap: 16px; padding: 16px; }
aside { background: #fff3bf; padding: 14px; border-radius: 8px; }
main { background: #f8f9fa; padding: 14px; border-radius: 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.card { background: white; border: 1px solid #dee2e6; border-radius: 8px; padding: 12px; }
footer { background: #343a40; color: #ced4da; text-align: center; padding: 14px; }
/* tablets and up: sidebar beside the content */
@media (min-width: 640px) {
.layout { grid-template-columns: 200px 1fr; }
}
</style>
<header><h1>City Bakery</h1></header>
<nav><a href="#">Home</a><a href="#">Menu</a><a href="#">Order</a><a href="#">Contact</a></nav>
<div class="layout">
<aside><strong>Opening hours</strong><p>Every day, 7am – 10pm.</p></aside>
<main>
<h2>Today's specials</h2>
<div class="cards">
<div class="card"><strong>Croissant</strong><p>Rs 180</p></div>
<div class="card"><strong>Banana bread</strong><p>Rs 250</p></div>
<div class="card"><strong>Cheesecake</strong><p>Rs 450</p></div>
</div>
</main>
</div>
<footer>© 2026 City Bakery</footer>4. How the Pieces Work
- Sticky footer:
bodyis a grid with rowsauto auto 1fr auto. The1frrow (the content) takes the leftover height, so the footer sits at the bottom even on short pages. - Mobile first:
.layoutis a single column by default; from 640px it becomes200px 1fr. - Cards:
repeat(auto-fit, minmax(150px, 1fr))gives as many columns as fit (Lecture 051). - Nav: Flexbox with
flex-wrap, so the links wrap on narrow screens.
5. Common Layout Patterns
| Pattern | Typical CSS |
|---|---|
| Centred content column | max-width: 1100px; margin-inline: auto; padding-inline: 16px; |
| Holy grail (sidebar, content, sidebar) | grid-template-columns: 200px 1fr 200px; |
| Full-screen hero | min-height: 100vh; display: grid; place-items: center; |
| Card grid | grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); |
Common Beginner Mistakes
1. Building desktop first. Start with one column, then add columns with min-width queries.
2. Fixed pixel widths for the whole page. Use max-width and fractions.
3. A footer floating halfway up short pages. Use the grid-rows trick (or Flexbox with flex: 1 on the content).
4. <div>s everywhere. Use header, nav, main, aside and footer (HTML Lecture 023).
Practice Questions
- Name the five common parts of a website layout.
- Write the grid columns for a 220px sidebar next to flexible content.
- How do you keep the footer at the bottom of a short page using Grid?
- Why start with a single-column layout?
- Centre the page content with a maximum width of 1000px.
Practice Answers
- Header, navigation, main content, sidebar (aside) and footer.
grid-template-columns: 220px 1fr;- Make
bodya grid withgrid-template-rows: auto 1fr auto(or similar) andmin-height: 100vh. - Phones get the simplest CSS, and larger screens add to it with
min-widthmedia queries. .container { max-width: 1000px; margin-inline: auto; }
Key Takeaways
- Header, nav, main, aside and footer make up most layouts.
- Grid places the big areas; Flexbox handles rows of items such as the nav.
- Mobile first: one column, then add columns with
min-widthqueries. min-height: 100vh+ rows with a1frcontent area keeps the footer down.