Module 5: CSS & Bootstrap
Teaching Principle: Generate CSS with AI, but open the page and confirm the layout actually looks right. Tweak values and re-check.
Lesson 5.1 — CSS Selectors and the Box Model
Duration: 50 minutes
Learning Objectives
- Link a CSS file to an HTML page.
- Use selectors: element, class, id, and grouping.
- Explain the box model: margin, border, padding, content.
- Style a simple card with the box model.
Instructor Notes
CSS controls appearance. Show how selectors target elements. Draw the box model on a whiteboard. Stress that padding is inside the border, margin is outside.
Presentation Outline
- What is CSS? (5 min).
- Linking CSS and basic rules (10 min).
- Selectors: element, class, id (15 min).
- The box model (15 min).
- Live styled card (5 min).
Demonstration
- Create
style.css and link it with <link>.
- Style
h1, a .card class, and a #main id.
- Add padding, border, margin to
.card.
- Open in browser and inspect the box model in dev tools.
AI Prompts
- "Act as a CSS teacher. Write CSS for a card with padding 20px, border 1px solid gray, and margin 10px. Explain the box model."
- "Explain the difference between id and class selectors in CSS with examples."
Starter Code
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Box</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="card" id="main">Hello Card</div>
</body>
</html>
/* style.css */
/* TODO: style .card with padding, border, margin */
Final Code
/* style.css */
body {
font-family: Arial, sans-serif;
}
.card {
padding: 20px;
border: 1px solid gray;
margin: 10px;
background: #f9f9f9;
}
#main {
color: navy;
}
Exercises
- Exercise 1: Change
.card padding to 40px and reload to see the difference.
- Exercise 2: Add a second
.card and confirm both are styled.
- Exercise 3: Use an id selector to make one card red.
Homework
- Assignment 1: Create a profile card with image, name, and bio styled via class selectors.
- Assignment 2: Ask AI to explain margin vs padding and paste the summary.
Quiz
- CSS stands for:
- a) Computer Style Sheets
- b) Cascading Style Sheets ✅
- c) Creative Style System
- d) Color Style Sheets
- To link CSS you use:
- a)
<script>
- b)
<link rel="stylesheet"> ✅
- c)
<style src>
- d)
<css>
- A class selector uses:
- Padding is space:
- a) Outside the border
- b) Inside the border, around content ✅
- c) The border itself
- d) Between pages
- Margin is space:
- a) Inside the element
- b) Outside the border, between elements ✅
- c) The font size
- d) The background
Lesson 5.2 — Flexbox Layout
Duration: 50 minutes
Learning Objectives
- Use
display: flex to align items.
- Control direction with
flex-direction.
- Center items with
justify-content and align-items.
- Build a responsive nav bar with Flexbox.
Instructor Notes
Flexbox is for 1-dimensional layouts (rows/columns). Show justify-content: center and align-items: center. Build a simple navbar to make it concrete.
Presentation Outline
- Why Flexbox? (5 min).
display: flex and direction (10 min).
- Justify and align (15 min).
- Wrap and gap (10 min).
- Live navbar build (10 min).
Demonstration
- Create a flex container with 3 items.
- Use
justify-content: space-between for a navbar.
- Use
align-items: center to vertically center.
- Add
gap and flex-wrap; resize window to see behavior.
AI Prompts
- "Write CSS using Flexbox to create a navbar with logo on the left and links on the right, vertically centered."
- "Explain justify-content vs align-items in Flexbox with examples."
Starter Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flex</title>
<style>
/* TODO: make .nav a flex container, space-between, centered */
</style>
</head>
<body>
<nav class="nav">
<span>Logo</span>
<span>Home</span>
<span>About</span>
</nav>
</body>
</html>
Final Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flex</title>
<style>
.nav {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 10px;
background: #eee;
}
</style>
</head>
<body>
<nav class="nav">
<span>Logo</span>
<span>Home</span>
<span>About</span>
</nav>
</body>
</html>
Exercises
- Exercise 1: Change
justify-content to center and observe.
- Exercise 2: Add 5 more links and use
flex-wrap.
- Exercise 3: Make a vertical flex column with
flex-direction: column.
Homework
- Assignment 1: Build a navbar with logo left and 4 links right using Flexbox.
- Assignment 2: Write one sentence explaining
justify-content.
Quiz
- Flexbox is best for:
- a) 3D graphics
- b) 1-dimensional row/column layouts ✅
- c) Databases
- d) Servers
- To start Flexbox you set:
- a)
display: block
- b)
display: flex ✅
- c)
float: flex
- d)
position: flex
justify-content controls:
- a) Vertical alignment
- b) Horizontal distribution (main axis) ✅
- c) Font size
- d) Color
align-items: center centers items:
- a) On the cross axis ✅
- b) On the page only
- c) In the database
- d) Never
gap in Flexbox sets:
- a) Space between flex items ✅
- b) Font color
- c) Image size
- d) Page title
Lesson 5.3 — CSS Grid
Duration: 50 minutes
Learning Objectives
- Use
display: grid for 2D layouts.
- Define columns with
grid-template-columns.
- Place items with
grid-area/spans.
- Build a responsive photo gallery grid.
Instructor Notes
Grid is for 2-dimensional layouts (rows AND columns). Compare with Flexbox. Show repeat(3, 1fr) for equal columns. Build a gallery that wraps responsively.
Presentation Outline
- Grid vs Flexbox (5 min).
grid-template-columns and rows (15 min).
fr unit and repeat() (10 min).
- Responsive with
auto-fit/minmax (10 min).
- Live gallery build (10 min).
Demonstration
- Create a grid container with
grid-template-columns: repeat(3, 1fr).
- Add 6 boxes; show 3-column layout.
- Change to
repeat(auto-fit, minmax(100px, 1fr)) for responsiveness.
- Resize window and verify reflow.
AI Prompts
- "Write CSS Grid code for a responsive gallery with 3 equal columns that becomes 1 column on small screens."
- "Explain the difference between Flexbox and CSS Grid for a beginner."
Starter Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Grid</title>
<style>
/* TODO: make .gallery a grid with 3 equal columns */
</style>
</head>
<body>
<div class="gallery">
<div>1</div><div>2</div><div>3</div>
<div>4</div><div>5</div><div>6</div>
</div>
</body>
</html>
Final Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Grid</title>
<style>
.gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.gallery div {
background: lightblue;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="gallery">
<div>1</div><div>2</div><div>3</div>
<div>4</div><div>5</div><div>6</div>
</div>
</body>
</html>
Exercises
- Exercise 1: Change to 4 columns and reload.
- Exercise 2: Use
auto-fit + minmax for responsiveness.
- Exercise 3: Make one item span 2 columns with
grid-column: span 2.
Homework
- Assignment 1: Build a 6-item responsive gallery with Grid.
- Assignment 2: Write 2 differences between Grid and Flexbox.
Quiz
- CSS Grid is best for:
- a) Only rows
- b) 2D layouts (rows and columns) ✅
- c) Servers
- d) Audio
- To start Grid you use:
- a)
display: grid ✅
- b)
display: flex
- c)
grid: on
- d)
float: grid
1fr means:
- a) 1 pixel
- b) One fraction of available space ✅
- c) 1 font
- d) 1 frame
repeat(3, 1fr) creates:
- a) 3 equal columns ✅
- b) 3 rows only
- c) 1 column
- d) A circle
- For responsive columns you can use:
- a)
auto-fit with minmax ✅
- b)
color: red
- c)
float
- d)
display: none
Lesson 5.4 — Bootstrap Components
Duration: 50 minutes
Learning Objectives
- Add Bootstrap via CDN to a page.
- Use Bootstrap buttons, cards, and a navbar.
- Apply the Bootstrap grid (
.container, .row, .col).
- Verify a Bootstrap layout renders correctly.
Instructor Notes
Bootstrap is a CSS framework that gives ready components. Show the CDN link. Emphasize it speeds up layout but you should still understand the underlying CSS. Verify with browser.
Presentation Outline
- What is Bootstrap? (5 min).
- Adding the CDN (10 min).
- Buttons and cards (15 min).
- Bootstrap grid system (10 min).
- Navbar + live page (10 min).
Demonstration
- Add Bootstrap CDN
<link> to <head>.
- Create a Bootstrap button and a card.
- Use
.container > .row > .col for a 3-column layout.
- Add a navbar; open page and verify styling.
AI Prompts
- "Generate a Bootstrap 5 page with a navbar, a card with an image and button, and a 3-column grid using the CDN."
- "Explain how to add Bootstrap to an HTML page using the CDN."
Starter Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap</title>
<!-- TODO: add Bootstrap CDN link -->
</head>
<body>
<!-- TODO: add a navbar, a card, and a 3-column grid -->
</body>
</html>
Final Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-light bg-light">
<span class="navbar-brand">MyShop</span>
</nav>
<div class="container mt-4">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Product 1</h5>
<button class="btn btn-primary">Buy</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Exercises
- Exercise 1: Add 2 more
.col-md-4 cards to complete the row.
- Exercise 2: Change the button color class (
btn-success).
- Exercise 3: Add a second navbar link and verify.
Homework
- Assignment 1: Build a 3-product Bootstrap store page with navbar and cards.
- Assignment 2: Ask AI "what is the Bootstrap grid system?" and summarize.
Quiz
- Bootstrap is:
- a) A programming language
- b) A CSS framework with ready components ✅
- c) A database
- d) A server
- To use Bootstrap quickly you add:
- a) A CDN link in
<head> ✅
- b) A Python file
- c) A MySQL query
- d) Nothing
- A Bootstrap button uses the class:
- a)
.button
- b)
.btn .btn-primary ✅
- c)
.link
- d)
.click
- Bootstrap grid columns use:
- a)
.col ✅
- b)
.box
- c)
.grid-item
- d)
.cell
- You should still learn CSS because:
- a) Bootstrap is enough alone
- b) Understanding CSS helps you customize and debug ✅
- c) It is required by law
- d) Bootstrap breaks otherwise
← Back to Module README
الوحدة 5: CSS و Bootstrap
مبدأ التدريس: ولّد كود CSS باستخدام الذكاء الاصطناعي، لكن افتح الصفحة وتأكد من أن التخطيط يبدو صحيحاً فعلاً. عدّل القيم وأعد الفحص.
الدرس 5.1 — محددات CSS ونموذج الصندوق
المدة: 50 دقيقة
ملخص: يغطي هذا الدرس أساسيات CSS: ربط ملف تنسيق بصفحة HTML، واستخدام المحددات (عنصر، فئة، معرّف، وتجميع)، ثم نموذج الصندوق المكوّن من المحتوى والحشو (padding) والحد (border) والهامش (margin). يتدرّب الطلاب على تنسيق بطاقة بسيطة. الهدف أن يفهم المتدرّب أن الحشو داخل الحد والهامش خارجه، مع عرض عملي بأدوات المطور.
الدرس 5.2 — تخطيط Flexbox
المدة: 50 دقيقة
ملخص: شرح Flexbox للتخطيطات أحادية البعد (صفوف أو أعمدة). يبدأ بتفعيل display: flex وضبط الاتجاه، ثم توزيع العناصر أفقياً بـ justify-content وتوسيطها رأسياً بـ align-items، مع الفجوة والالتفاف. ينتهي ببناء شريط تنقل متجاوب عملياً.
الدرس 5.3 — شبكة CSS (Grid)
المدة: 50 دقيقة
ملخص: يقدّم CSS Grid للتخطيطات ثنائية الأبعاد (صفوف وأعمدة معاً). يشرح تعريف الأعمدة بـ grid-template-columns، ووحدة fr مع repeat()، والتجاوب عبر auto-fit و minmax. يُختتم بمعرض صور متجاوب يلتف تلقائياً عند تغيير حجم النافذة.
الدرس 5.4 — مكونات Bootstrap
المدة: 50 دقيقة
ملخص: يتعرّف الطلاب على Bootstrap كإطار عمل CSS يوفّر مكونات جاهزة. يضيفونه عبر رابط CDN في الترويسة، ثم يستخدمون الأزرار والبطاقات وشريط التنقل ونظام الشبكة (.container، .row، .col)، مع التأكيد على أهمية فهم CSS الأساسي للتخصيص وتصحيح الأخطاء.
→ الرجوع إلى ملاحظات الوحدة