CSS Block and Inline Elements - Guided Notes

CSCI 3403 - Web Programming | Day 12

Name: _________________________________ Date: _____________

📚 Learning Objectives: Understand Normal Flow, differentiate between block and inline elements, know when to use divs and spans, apply display properties effectively

🌊 Normal Flow

Definition

Normal flow is _________________________________________

_________________________________________

Key Concepts of Normal Flow

  1. Elements render in _________________ order
  2. Block elements stack _________________
  3. Inline elements flow _________________
  4. No _________________ unless positioned

🎨 The Display Property

Common Display Values

/* Fill in what each does: */ display: ________; /* Elements stack vertically */ display: ________; /* Elements flow horizontally */ display: ________; /* Best of both worlds */ display: ________; /* Hides the element completely */ display: flex; /* Coming next lesson! */

📦 Block Elements

Characteristics (Check all that apply)

Common Block Elements

Category Elements (List 3-4)
Structural _________________________________________
Headings _________________________________________
Content _________________________________________
Lists _________________________________________
Draw how these block elements would display:
<div>First Block</div>
<p>Second Block</p>
<h3>Third Block</h3>

➡️ Inline Elements

Characteristics (Check all that apply)

Common Inline Elements

List 6 inline elements:

  1. _________________
  2. _________________
  3. _________________
  4. _________________
  5. _________________
  6. _________________
⚠️ Warning: Vertical padding/margin on inline elements _________________________________________

⚖️ Block vs Inline Comparison

Property Block Inline
Line breaks? _________________ _________________
Default width _________________ _________________
Can set width/height? _________________ _________________
Vertical margin/padding _________________ _________________

🎯 Inline-Block: The Middle Ground

Inline-block elements combine features of both:

/* When would you use inline-block? */ .navigation-item { display: ________________; padding: 10px 20px; /* Why does this work now? */ margin: 5px; /* _________________________ */ }

📦 Generic Containers: Divs and Spans

Property <div> <span>
Default display _________________ _________________
Semantic meaning _________________ _________________
Common use _________________________ _________________________
Best Practice: Always use semantic HTML first! Only use div/span when _________________________________________

💻 Practice Problems

1. Identify the Display Type

Write 'block', 'inline', or 'inline-block' for each scenario:

  1. Navigation links that sit side-by-side: _________________
  2. Main content container: _________________
  3. Bold text within a paragraph: _________________
  4. Cards in a horizontal layout: _________________
  5. Page header: _________________

2. Fix the CSS

/* This inline element needs vertical spacing. How do you fix it? */ span.badge { _______________________ padding: 10px 15px; margin: 10px 5px; }

3. Predict the Output

How many lines will this render on?

<div>Line 1</div> <span>Line 2</span> <span>Line 3</span> <div>Line 4</div>

Answer: _______ lines

Explanation: _________________________________________

📋 Quick Reference

Changing Display Property

/* Override any element's default display */ .make-block { display: block; } .make-inline { display: inline; } .make-inline-block { display: inline-block; } .hide-element { display: none; }

Common Gotchas to Remember

📚 Homework

Part 1: CSS Exercises

Complete from The Odin Project repository:

Repository: TheOdinProject/css-exercises/foundations/block-and-inline

Part 2: Style Your Recipe Page

Resources to Review

📝 Additional Notes

Use this space for any additional notes during the lecture: