From the CSS Media Queries chapter, you’ve discovered the ability to utilize media queries for crafting distinct layouts tailored to diverse screen sizes and devices..
For instance, to establish a two-column layout for larger screen sizes and a one-column layout for smaller screens like phones and tablets, you can adjust the flex-direction from row to column at a designated breakpoint (e.g., 800px in the example below).
Example
.flex-container { display: flex; flex-direction: row; } /* Responsive layout – makes a one column layout instead of a two-column layout */ @media (max-width: 800px) { .flex-container { flex-direction: column; } } |
An alternative approach involves modifying the percentage of the flex property of the flex items to generate varying layouts tailored to distinct screen sizes. It’s important to note that for this example to function properly, flex-wrap: wrap; must also be included on the flex container.
Example
.flex-container { |
Responsive Image Gallery using Flexbox
Utilize flexbox to craft a responsive image gallery that adjusts its layout between displaying four, two, or full-width images based on the screen size.
Employ flexbox to design a responsive website featuring a dynamic navigation bar and adaptable content layout.