Understanding display: flex in CSS
display: flex transforms an element into a flex container, enabling the Flexbox layout model. This allows its direct children (flex items) to be aligned and distributed along both the main and cross axes with ease.
display: flex creates a block-level flex container; display: inline-flex creates an inline-level flex container.
Direct child elements become flex items, which can grow, shrink, and align automatically within the container.
Flexbox provides one-dimensional layout control (row or column) along the main axis.
It simplifies spacing, alignment, and responsiveness compared to floats or inline-block layouts.
Flex properties like justify-content, align-items, and flex-wrap control the layout of flex items inside the container.
In this example, the .container becomes a flex container, arranging its children .item along the main axis with equal spacing and centering them along the cross axis.
Use display: flex for one-dimensional layouts where items need to be aligned in a row or column.
Combine with flex-wrap for responsive designs where items may need to wrap onto multiple lines.
Understand the main axis vs cross axis to apply proper alignment.
Test across different browsers and screen sizes to ensure consistent layout behavior.
How would you center a button and a text label horizontally inside a header using flexbox?
What happens if you set display: flex on a div with three child divs but don’t specify any flex properties?
If you have two flex items and one has flex: 2 while the other has flex: 1, how will they divide the available space?
A responsive card grid breaks on mobile — the items overflow the container even though you set flex-wrap: wrap. What could be causing this and how would you debug it?
You’re building a navigation bar that should collapse into a vertical stack on small screens, but the items are still wrapping oddly. What flex properties might you be missing or misusing?
Why might a flex item with text content appear truncated on some browsers even though it has flex: 1 and no explicit width?
You’re designing a dynamic dashboard with resizable panels that use flexbox. How would you handle performance when users resize multiple panels simultaneously, and what edge cases might cause layout thrashing?
How would you structure a complex form layout with nested flex containers that needs to support RTL, screen readers, and dynamic field additions without breaking accessibility or responsiveness?
A legacy component uses flexbox for a list of cards, but it’s causing layout shifts during lazy loading. What’s the root cause and how would you fix it without rewriting the entire component?
You’re leading a migration from CSS Grid to Flexbox for a large-scale UI library used across 50+ products. What tradeoffs do you weigh in terms of maintainability, browser support, and developer ergonomics?
How would you design a cross-team CSS architecture standard for flexbox usage that prevents layout bugs when teams integrate components with conflicting flex behaviors?
A legacy app uses flexbox for layout but has inconsistent alignment across browsers due to vendor prefixes and outdated polyfills. How do you prioritize and execute a long-term cleanup without breaking existing features?