๐Ÿงฑ Assignment: Building Blocks with Display Properties

Instructions

Goal: Master block, inline, and inline-block display properties by building visual layouts.

Time: 60-90 minutes

Tools needed: Text editor and web browser

Submission: Create a file named building-blocks.html

๐Ÿ“š Display Properties Reference

Property Behavior Width/Height Margins
display: block; Takes full width, starts new line โœ“ Can set โœ“ All sides work
display: inline; Flows with text, no line break โœ— Cannot set Only left/right work
display: inline-block; Flows inline but acts like block โœ“ Can set โœ“ All sides work

๐ŸŽฏ Visual Demonstration

Block Elements

Block 1
Block 2
Block 3

Each takes full width and stacks vertically

Inline Elements

Inline 1 Inline 2 Inline 3

They flow horizontally like text

Inline-Block Elements

Box 1
Box 2
Box 3

Flow horizontally but can have width/height like blocks

๐Ÿ“ Tasks

Task 1: Color Blocks (15 points)

Create 3 colored blocks using display: block;

Requirements:

Example Code:

<div style="display: block; background-color: #667eea; 
            height: 100px; padding: 20px; margin: 10px 0; 
            color: white;">
    Block 1
</div>
        

Expected Result:

Block 1
Block 2
Block 3

Task 2: Inline Tags (15 points)

Create a paragraph with inline highlighted words.

Requirements:

Example Code:

<p style="font-size: 18px;">
    I love <span style="display: inline; background-color: yellow; 
    padding: 3px;">HTML</span> and 
    <span style="display: inline; background-color: lightblue; 
    padding: 3px;">CSS</span>.
</p>
        

Expected Result:

I love HTML and CSS and JavaScript for web development.

Task 3: Button Row with Inline-Block (20 points)

Create a row of buttons using display: inline-block;

Requirements:

Example Code:

<div style="display: inline-block; width: 150px; height: 50px;
            background-color: #667eea; color: white; 
            text-align: center; line-height: 50px; 
            margin: 5px; border-radius: 5px;">
    Button 1
</div>
        

Expected Result:

Home
About
Services
Contact

Task 4: Card Grid (25 points)

Create a grid of product cards using display: inline-block;

Requirements:

Example Code:

<div style="display: inline-block; width: 250px; 
            border: 2px solid #ddd; padding: 20px; 
            margin: 10px; border-radius: 8px; 
            vertical-align: top;">
    
    <h3 style="margin-top: 0; color: #667eea;">Product 1</h3>
    
    <div style="width: 100%; height: 150px; 
                background-color: #e9ecef; margin: 10px 0; 
                text-align: center; line-height: 150px; 
                color: #666;">
        Image Placeholder
    </div>
    
    <p>Quality product description here.</p>
    
    <p style="color: #28a745; font-size: 24px; 
              font-weight: bold;">$49.99</p>
    
</div>

<!-- Repeat 5 more times with different products -->
        

Example Output:

Product 1

Image

Quality product description here.

$49.99

Product 2

Image

Quality product description here.

$59.99

Product 3

Image

Quality product description here.

$39.99

Task 5: Mixed Layout (25 points)

Create a page header combining all three display types.

Requirements:

Structure:

<div style="display: block; background-color: #2c3e50; 
            padding: 20px;">
    
    <!-- Logo -->
    <div style="display: inline-block; width: 100px; 
                height: 100px; background-color: #667eea; 
                color: white; text-align: center; 
                line-height: 100px;">
        LOGO
    </div>
    
    <!-- Nav Links -->
    <div style="display: inline-block; margin-left: 50px;">
        <a href="#" style="display: inline-block; color: white; 
                          padding: 10px 20px; margin: 0 5px;">
            Home <span style="display: inline; background-color: red; 
                              padding: 2px 6px; border-radius: 10px; 
                              font-size: 12px;">New</span>
        </a>
    </div>
    
</div>
        

Expected Result:

LOGO
Home New Products 5 About

Task 6: Challenge - Dashboard Layout (30 points)

Build a mini dashboard combining everything.

Requirements:

Sample Output:

150
Total Users
45
Orders Today
$2,450
Revenue
98%
Satisfaction

๐Ÿงช Experiments to Try

Try These Tests:

  1. Set width on an inline span - what happens?
  2. Add top/bottom margin to inline elements - do they work?
  3. Create inline-block elements with different heights - how do they align?
  4. Mix block and inline-block elements - what happens?
  5. Change div to display: inline - observe the difference

๐Ÿ“ Understanding Questions

Answer these in comments in your HTML:

  1. When would you use inline-block instead of block?
  2. Why can't inline elements have width and height?
  3. What's the main advantage of inline-block over inline?
  4. How do you center inline-block elements?
  5. Can you change a span to display: block? What happens?

โœ… Submission Checklist

๐Ÿ“Š Grading Rubric

Task Points
Task 1: Color Blocks 15
Task 2: Inline Tags 15
Task 3: Button Row 20
Task 4: Card Grid 25
Task 5: Mixed Layout 25
Task 6: Dashboard 30
Understanding Questions 10
Total 140 points

๐Ÿ’ก Pro Tips: