bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Modern Layout
CSS•Modern Layout

CSS Responsive Flexbox

Responsive Flexbox

You learned from the CSS Media Queries chapter that you can use media queries to create different layouts for different screen sizes and devices.

Example

Formatted code
.flex-container {
  display: flex;
  flex-direction: row;
} .flex-item {
background-color: #f1f1f1;
padding: 10px;
font-size: 30px;
text-align: center;
width: 100%;
}
/* Make a one column-layout instead of three-column layout */
@media
(max-width: 600px) { .flex-container {
    flex-direction: column;
  }
}

Live preview

Another way is to change the percentage of the flex property of the flex items to create different layouts for different screen sizes. Note that we also have to include flex-wrap: wrap; on the flex container for this example to work:

Example

Formatted code
.flex-container {
  display: flex;
  flex-wrap: wrap;
} .flex-item {
background-color: #f1f1f1;
padding: 10px;
text-align: center;
font-size: 30px;
flex: 33.3%;
}
/* Make a one
column-layout instead of a three-column layout */
@media (max-width: 600px) { .flex-item {
    flex: 100%;
  }
}

Live preview

Responsive Image Gallery using Flexbox

Here, we use media queries together with flexbox to create a responsive image gallery:

Responsive Website using Flexbox

Use flexbox to create a responsive website, containing a flexible navigation bar and flexible content:

Previous

Responsive Web Design - Images

Next

CSS Grid Items

This chapter

Overview
24

Lessons

64m

Read time

1. CSS Flexbox2. CSS Grid Layout3. Responsive Web Design4. CSS Flex Container5. CSS Grid Container6. Responsive Web Design - The Viewport7. CSS Flexbox justify-content8. CSS Grid Tracks9. Responsive Web Design - Building a Grid View10. CSS Flexbox Align11. CSS Grid Gap12. Responsive Web Design - Media Queries13. CSS Flex Items14. CSS Grid Container - Align Grid Content15. Responsive Web Design - Images16. CSS Responsive Flexbox17. CSS Grid Items18. Responsive Web Design - Frameworks19. CSS Naming Grid Items20. Responsive Web Design - Templates21. CSS Grid Items - Alignment22. CSS Grid Items - Order23. CSS 12-Column Grid Layout24. CSS @supports Rule

On this page

Responsive FlexboxResponsive Image Gallery using FlexboxResponsive Website using Flexbox