🟒 LESSON 4 PRACTICAL

🟒 LESSON 4 PRACTICAL β€” Display & Layout

🎯 Goal

Understand:

  • Why elements stack or stay inline
  • Control layout using display
  • Prepare for Flexbox (next lesson πŸ”₯πŸ”₯)

CORE IDEA

Every HTML element has a default display type:

1. Block elements

  • Take full width
  • Start on new line

Examples:

  • <div>, <h1>, <p>

2. Inline elements

  • Stay on same line
  • Only take needed width

Examples:

  • <span>, <a>

πŸ§‘β€πŸ’» STEP 1: Test Display Types

Add this to your HTML:

<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>

🎨 STEP 2: Style Them

.box {
    background: white;
    padding: 20px;
    margin: 10px;
    border: 2px solid black;
}

πŸ‘‰ You’ll see:

  • Boxes stacked vertically (block behavior)

πŸ”„ STEP 3: Change to INLINE

.box {
    display: inline;
}

πŸ‘‰ Result:

  • They go in one line
  • BUT width/height won’t work properly ⚠️

⚑ STEP 4: Use INLINE-BLOCK (IMPORTANT πŸ”₯)

.box {
    display: inline-block;
    width: 150px;
}

πŸ‘‰ Now:

  • Same line βœ…
  • Width works βœ…

🚫 STEP 5: Hide Elements

.box {
    display: none;
}

πŸ§ͺ STEP 6: Real Practice

Modify your cards:

.card {
    display: inline-block;
    width: 300px;
    margin: 20px;
}

πŸ‘‰ Now cards sit side by side

🎯 CHALLENGE

Create a layout like this:

[ Card ]   [ Card ]   [ Card ]

πŸ‘‰ Requirements:

  • 3 cards in one row
  • Equal width
  • Spacing between them

πŸ’‘ PRO INSIGHT

Display TypeWhen to Use
blockSections/layout
inlineText styling
inline-blockSmall layouts

πŸ‘‰ BUT…

⚠️ Real developers don’t rely on this much anymore…

You may also like...

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *