CHAPTER 70

CSS Flex Responsive

Learn how Flexbox can create layouts that adapt to different screen sizes.

01. What is CSS Flex Responsive?

Flexbox can rearrange elements as screen size changes.
flex-wrap can allow items to move to new lines.
flex-direction can change between row and column layouts.

02. Syntax

.container { display: flex; flex-wrap: wrap; } @media(max-width:700px) { .container { flex-direction: column; } }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>

.container {
    display: flex;
    gap: 20px;
}

.card {
    flex: 1;
    padding: 30px;
    background: #dbeafe;
}

@media(max-width:700px) {

    .container {
        flex-direction: column;
    }

}

</style>
</head>
<body>

<div class="container">

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

</div>

</body>
</html>

04. Important Points

✓ Use flexible widths where possible.
✓ Use wrapping for variable content.
✓ Media queries can change flex direction.
✓ Always test layouts on actual mobile sizes.

05. Common Mistakes

⚠ Using fixed widths that overflow.
⚠ Forgetting gaps on small screens.
⚠ Testing only on desktop.

06. Real World Use

Responsive Flexbox is widely used for course cards, product grids, navigation and landing page sections.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Mobile Flex Layout

Create three cards in a row on desktop and stack them vertically on mobile.