Responsive Layout Essentials: Flexbox u0026 CSS Grid Quiz Quiz

Test your understanding of responsive web layout techniques with this quiz on Flexbox, CSS Grid, and media queries. Evaluate your knowledge of fluid units, alignment, gap usage, and common patterns for building modern, adaptable designs.

  1. Flexbox Direction

    Which property sets the main axis direction for flex items when using Flexbox?

    1. justify-content
    2. align-items
    3. grid-auto-flow
    4. flex-direction

    Explanation: The flex-direction property determines whether flex items are arranged as a row or a column. Justify-content and align-items control alignment, not direction. Grid-auto-flow is related to CSS Grid, not Flexbox.

  2. Fluid Units

    When designing a fully responsive component, which unit type ensures width adjusts with the viewport size?

    1. cm
    2. vw
    3. px
    4. pt

    Explanation: The vw unit represents a percentage of the viewport's width, making it ideal for fluid layouts. Pixels (px), points (pt), and centimeters (cm) are fixed or print-related units and do not respond to viewport changes.

  3. Grid Track Sizing

    Which CSS Grid value allows a column to take up remaining space after other columns are sized?

    1. px
    2. fr
    3. em
    4. min-content

    Explanation: The fr unit distributes available space among grid tracks based on their ratio. The em unit is relative to font size, min-content is a sizing keyword, and px is a fixed sizing unit.

  4. Flexbox Alignment Shortcut

    To center a flex item both horizontally and vertically in a container, which pair of Flexbox properties is most commonly used?

    1. width and float
    2. grid-template and gap
    3. display and flex-wrap
    4. justify-content and align-items

    Explanation: The combination of justify-content and align-items centers items along the main and cross axes. Display and flex-wrap set display and wrapping behavior. Grid-template and gap are Grid properties. Width and float do not provide accurate centering in Flexbox.

  5. Media Query Syntax

    What is the correct syntax for applying styles only when the viewport is at least 600px wide?

    1. @media width u003E= 600px
    2. @media (max-width: 600px)
    3. @media (min-width: 600px)
    4. @media min-width 600px

    Explanation: The correct syntax uses @media with (min-width: 600px) in parentheses. The other options use incorrect formatting, keywords, or use max-width which targets viewports smaller than 600px.

  6. Gaps in Flexbox and Grid

    Which CSS property can add space between items in both Flexbox and Grid layouts?

    1. border
    2. row-span
    3. gap
    4. margin-top

    Explanation: The gap property is designed to add spacing directly between items for both Flexbox and Grid layouts. Margin-top only affects vertical margins, border adds a line not spacing, and row-span is not a valid CSS property.

  7. Common Responsive Pattern

    Which layout pattern often uses media queries to switch from a column layout on mobile devices to a row layout on larger screens?

    1. Stack to Row
    2. Float Grid
    3. Centered Grid
    4. Sticky Header

    Explanation: Stack to Row is a common responsive pattern where content stacks vertically on small screens and shifts to a horizontal row on larger screens. Float Grid and Centered Grid aren't standard pattern names, and Sticky Header refers to header positioning, not overall layout.

  8. Aligning Items in Grid

    To align all grid items along the horizontal axis within their cells, which CSS Grid property should you use?

    1. float
    2. flex-shrink
    3. justify-items
    4. align-content

    Explanation: justify-items in a grid layout aligns content horizontally within each cell. Align-content controls spacing between grid tracks, flex-shrink is a Flexbox property, and float is outdated and unsuitable for grid alignment.

  9. Flexible Flex Items

    To allow a flex item to grow and fill unused space in a flex container, which property should you set?

    1. flex-grow
    2. margin-left
    3. order
    4. align-self

    Explanation: flex-grow tells a flex item to expand and share unused space. Align-self changes alignment for a single item, margin-left adds spacing only, and order repositions items but doesn’t affect size.

  10. Auto-Filling Grid Columns

    Which value in the grid-template-columns property creates as many columns as fit based on available space?

    1. repeat(auto-fit, minmax(200px, 1fr))
    2. span 2
    3. center
    4. none

    Explanation: repeat(auto-fit, minmax(200px, 1fr)) automatically fits as many columns as possible in the container. Span 2 applies to grid item placement, none is not valid for grid-template-columns, and center is a value for alignment, not column creation.

  11. Media Queries Use Case

    Which scenario best illustrates when to use a media query?

    1. Adding a border-radius to a button
    2. Changing font size for screens wider than 1000px
    3. Aligning a paragraph with text-align left
    4. Setting a div’s color using rgb

    Explanation: Altering styles based on screen size is the core purpose of media queries. The other options pertain to styles that do not require conditional responsiveness or device-based changes.

  12. Grid Row and Column Placement

    To place a grid item in the second row and third column, which properties can you use?

    1. padding and border
    2. grid-row and grid-column
    3. margin-top and margin-left
    4. float and clear

    Explanation: grid-row and grid-column specify the position of a grid item within grid rows and columns. Margin and padding control spacing, border adds a line, and float/clear are for older layout methods not compatible with Grid placement.

  13. Flexbox Wrap Control

    Which Flexbox property lets items wrap onto multiple lines when they exceed the container width?

    1. position
    2. overflow
    3. align-items
    4. flex-wrap

    Explanation: flex-wrap enables flex items to move onto additional lines as needed, maintaining responsiveness. Overflow manages content outside the box, align-items controls alignment, and position handles layout but not wrapping.

  14. Using min-width in Media Queries

    Why is min-width often preferred over max-width in mobile-first responsive design?

    1. max-width is not a real media query
    2. min-width only sets container width
    3. min-width sets a limit below which styles apply
    4. min-width targets larger screens as breakpoints

    Explanation: Using min-width allows you to apply styles for progressively larger screens, which aligns with a mobile-first approach. Max-width targets smaller viewports instead. Max-width is a valid media query but less preferred for mobile-first. Min-width in this context does not simply set container width.

  15. Dynamic Flex Basis

    Which property controls the initial main size of a flex item before remaining space is distributed?

    1. flex-basis
    2. gap
    3. place-items
    4. flex-order

    Explanation: flex-basis determines the starting size of a flex item before growing or shrinking. Flex-order is incorrect, gap is for spacing, and place-items is used for grid alignment.

  16. Grid Layout Use Case

    Which layout would benefit most from using CSS Grid rather than Flexbox?

    1. A single horizontal navigation bar
    2. A two-dimensional card gallery with both rows and columns
    3. Vertically stacking notifications
    4. Centering a single button in a container

    Explanation: CSS Grid excels at structuring layouts with both rows and columns, such as a card gallery. Flexbox is ideal for single-direction layouts like navigation bars or vertical stacks. Centering a single button doesn't require the complexity of Grid.