9.1 CSS Flexbox & Responsive Design
Lesson 5: CSS Flexbox & Responsive Design
Objective:
Learn to create flexible layouts using Flexbox and media queries for responsive design.
Introduction to Flexbox

Flex Containers and Flex Items: A flex container is an element that enables Flexbox layout, and its direct children are considered flex items. To start using Flexbox, define a container as a flex container:
Key Flexbox Properties:
flex-direction: Defines the direction of the flex items within the container. Values includerow(default),column,row-reverse, andcolumn-reverse.justify-content: Controls how flex items are distributed along the main axis (horizontal or vertical depending onflex-direction). Common values:flex-start,flex-end,center,space-between,space-around.align-items: Aligns flex items along the cross axis (perpendicular to the main axis). Common values:flex-start,flex-end,center,stretch.flex-wrap: Controls whether flex items wrap onto multiple lines. By default, flex items are on a single line (nowrap), but this can be set towrapfor multi-line layouts.flexbox display: the display value`
flex`defines the container as a block element, however, the value `inline-flex`defines the element as inline element.
Building a Flexbox Layout
Creating a Basic Responsive Layout Using Flexbox: To demonstrate Flexbox, let’s create a simple layout with three columns that adjust according to screen size.
Understanding Alignment and Spacing with Flexbox: By adjusting
justify-contentandalign-items, you can control the horizontal and vertical alignment of flex items within the container.
Responsive Design with Media Queries
Using Media Queries to Create Responsive Designs: Media queries allow you to apply different styles based on the viewport size (or other characteristics). For example, you can adjust the layout for screens narrower than 600px:
Combining Flexbox and Media Queries
Creating a Mobile-First Design with Flexbox and Media Queries: In a mobile-first approach, you design for smaller screens first and then progressively enhance the layout for larger screens using media queries.
Last updated