Course Content
Project file
0/1
Complete Web Designing Course for Beginners

Lesson 4.7 – Flexbox Advanced Layout

🌟 Building Professional and Responsive Layouts Using Advanced Flexbox Properties


🎯 Learning Objectives

After completing this lesson, students will be able to:

βœ… Understand Advanced Flexbox Features

βœ… Use Flex Wrap

βœ… Use Flex Grow

βœ… Use Flex Shrink

βœ… Use Flex Basis

βœ… Create Responsive Layouts

βœ… Build Professional Website Sections

βœ… Design Modern Web Interfaces


πŸ“– Introduction

In the previous lesson, we learned:

Β 
display:flex;
Β 

which places items in a row.

Example:

Β 
HTML   CSS   JS
Β 

Looks great.

But what happens when:

Β 
HTML CSS JS React Bootstrap Python Java
Β 

Many items are added?


Without proper Flexbox settings:

Β 
HTML CSS JS React Bootstrap Python Java
Β 

Everything becomes crowded.


To solve this problem we use:

πŸš€ Advanced Flexbox Properties


🌟 Advanced Flexbox Properties

Important properties:

βœ… flex-wrap

βœ… flex-grow

βœ… flex-shrink

βœ… flex-basis

βœ… align-content


🎯 Flex Wrap

By default:

flex-wrap:nowrap;
Β 

Meaning:

All items stay on one line.


Example

.container{

display:flex;

flex-wrap:nowrap;

}

Problem

If too many items exist:

Β 
HTML CSS JS React Bootstrap Python Java
Β 

Items may overflow.


🌟 Wrap Property

flex-wrap:wrap;

Meaning:

Move extra items to next line.


Example

.container{

display:flex;

flex-wrap:wrap;

}

Output

Β 
HTML CSS JS

React Bootstrap Python

Java
Β 

Why Use Wrap?

Useful for:

βœ… Product Cards

βœ… Gallery Layouts

βœ… Course Cards

βœ… Team Sections


🎯 Flex Grow

Controls how much extra space an item should take.


Syntax

flex-grow:value;

Example

.item1{

flex-grow:1;

}

Meaning:

Item grows to fill available space.


Example

HTML

<div class="container">

<div class="item1">HTML</div>

<div>CSS</div>

<div>JS</div>

</div>
Β 

CSS

.item1{

flex-grow:1;

}

Result

HTML box becomes larger.


Example

.item1{

flex-grow:2;

}

Meaning:

Takes twice the available space.


Visual Example

Β 
HTMLHTMLHTMLHTML

CSS

JS
Β 

🎯 Flex Shrink

Controls shrinking when space becomes small.


Syntax

flex-shrink:value;

Example

flex-shrink:1;

Default behavior.

Element shrinks if needed.


Example

flex-shrink:0;

Meaning:

Β 
Do not shrink
Β 

Example

.box{

width:300px;

flex-shrink:0;

}

Useful for:

βœ… Important Buttons

βœ… Important Cards

βœ… Logos


🎯 Flex Basis

Defines initial size before growing or shrinking.


Syntax

flex-basis:value;

Example

flex-basis:200px;

Meaning:

Initial width = 200px.


Example

.box{

flex-basis:250px;

}

Result

Each item starts with 250px width.


Why Use Flex Basis?

Useful for:

βœ… Card Layouts

βœ… Product Grids

βœ… Service Sections


🎯 Flex Shorthand

Instead of:

flex-grow:1;

flex-shrink:1;

flex-basis:200px;

Use:

flex:1 1 200px;

Meaning:

Β 
Grow = 1

Shrink = 1

Basis = 200px
Β 

🌟 Align Content

Used when multiple rows exist.

Works with:

flex-wrap:wrap;

Syntax

align-content:value;

Center

align-content:center;

Space Between

align-content:space-between;

Space Around

align-content:space-around;

Example

.container{

display:flex;

flex-wrap:wrap;

align-content:center;

}

🎯 Responsive Card Layout

HTML

<div class="container">

<div class="card">HTML</div>

<div class="card">CSS</div>

<div class="card">JavaScript</div>

<div class="card">React</div>

<div class="card">Bootstrap</div>

<div class="card">Python</div>

</div>

CSS

.container{

display:flex;

flex-wrap:wrap;

gap:20px;

}

.card{

flex:1 1 200px;

border:2px solid blue;

padding:20px;

}

Result

Cards automatically adjust according to screen size.


🌟 Building a Service Section

HTML

<div class="services">

<div class="service">

Web Design

</div>

<div class="service">

App Development

</div>

<div class="service">

Digital Marketing

</div>

</div>

CSS

.services{

display:flex;

flex-wrap:wrap;

gap:20px;

}

.service{

flex:1 1 250px;

background-color:lightblue;

padding:20px;

}

Result

Professional service cards.


🎯 Equal Width Columns

CSS

.column{

flex:1;
}

HTML

<div class="column">

HTML

</div>

<div class="column">

CSS

</div>

<div class="column">

JS

</div>

Result

All columns become equal width.


🌟 Complete Example

HTML

<div class="container">

<div class="box">HTML</div>

<div class="box">CSS</div>

<div class="box">JS</div>

<div class="box">React</div>

<div class="box">Bootstrap</div>

<div class="box">Python</div>

</div>

CSS

.container{

display:flex;

flex-wrap:wrap;

gap:20px;

}

.box{

flex:1 1 200px;

background-color:lightyellow;

border:2px solid orange;

padding:20px;

text-align:center;

}

🎯 Expected Output

Responsive boxes arranged automatically.

Desktop:

Β 
HTML CSS JS React Bootstrap Python
Β 

Mobile:

Β 
HTML

CSS

JS

React

Bootstrap

Python
Β 

πŸ’» Complete Practical Program

HTML

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="style.css">

</head>

<body>

<div class="container">

<div class="card">HTML</div>

<div class="card">CSS</div>

<div class="card">JavaScript</div>

<div class="card">React</div>

<div class="card">Bootstrap</div>

<div class="card">Python</div>

</div>

</body>

</html>

CSS

.container{

display:flex;

flex-wrap:wrap;

gap:20px;

}

.card{

flex:1 1 200px;

background-color:lightblue;

border:2px solid blue;

padding:20px;

text-align:center;

font-size:20px;

}

🏫 Real World Examples

E-Commerce Products

flex-wrap:wrap;

Team Member Cards

flex:1 1 250px;

Course Cards

gap:20px;

Service Sections

display:flex;

⚠️ Common Beginner Mistakes


Mistake 1

Forgetting Flex Wrap

Wrong:

display:flex;

Lots of cards may overflow.


Use:

flex-wrap:wrap;

Mistake 2

Using Fixed Width

Wrong:

width:300px;

Not responsive.


Better:

flex:1 1 250px;

Mistake 3

Using Large Flex Grow Values

Wrong:

flex-grow:10;

May create uneven layouts.


🌟 Best Practices

βœ… Use flex-wrap for responsiveness.

βœ… Use gap instead of margins.

βœ… Use flex-basis for card sizes.

βœ… Use flex shorthand.

βœ… Test layouts on mobile screens.


πŸ† Mini Project – Course Card Section

Create six course cards:

Β 
HTML

CSS

JavaScript

React

Bootstrap

Python
Β 

Apply:

βœ… display:flex

βœ… flex-wrap:wrap

βœ… gap:20px

βœ… flex:1 1 200px


πŸ“ Practical Activity

Create a:

Service Section

Containing:

  • Web Design
  • Web Development
  • App Development
  • Digital Marketing

Display all cards responsively.


πŸ“‹ Assignment

Assignment 4.7

  1. What is flex-wrap?
  2. What is flex-grow?
  3. What is flex-shrink?
  4. What is flex-basis?
  5. What is the flex shorthand property?
  6. Create a responsive card layout.
  7. Create a service section using Flexbox.

🧠 Quiz

Q1. Which property moves items to the next line?

A. flex-grow

B. flex-wrap

C. flex-basis

D. flex-shrink

βœ… Answer: B


Q2. Which property controls growth?

A. flex-grow

B. flex-wrap

C. gap

D. width

βœ… Answer: A


Q3. Which property defines initial size?

A. flex-size

B. flex-grow

C. flex-basis

D. flex-width

βœ… Answer: C


Q4. Which shorthand combines grow, shrink, and basis?

A. flex-all

B. flex

C. flex-layout

D. flexbox

βœ… Answer: B


Q5. Which property creates spacing between flex items?

A. padding

B. margin

C. gap

D. border

βœ… Answer: C


πŸ“Œ Lesson Summary

βœ… Flexbox can create advanced responsive layouts.

βœ… flex-wrap moves items to new rows.

βœ… flex-grow controls expansion.

βœ… flex-shrink controls shrinking.

βœ… flex-basis defines initial size.

βœ… flex: 1 1 200px is a common professional pattern.

βœ… Advanced Flexbox is used in modern websites and applications.

Scroll to Top