Implement a fixed-width sidebar with Flexbox and CSS Grid

This tests Flexbox as one-dimensional versus Grid as 2-dimensional. A strong answer covers Flexbox with flex: 1 on main and flex: none on sidebar, and Grid with grid-template-columns: 250px 1fr. Red flag: claiming Grid is always superior or ignoring overflow.
What's really being asked
The interviewer wants to see if you treat layout methods as tools with tradeoffs, not just syntax. They are checking whether you understand that Flexbox is fundamentally one-dimensional while Grid is two-dimensional, and whether you can articulate when a one-row layout is better served by the simpler model. They also want to hear specifics about sizing, overflow, and gap handling.
The full answer
First, the Flexbox implementation: set the container to display flex, give the sidebar flex: none or flex: 0 0 250px so it keeps its fixed width, and give the main content area flex: 1 1 auto so it absorbs leftover space. Second, the Grid implementation: set the container to display grid and define grid-template-columns: 250px 1fr so the first track is fixed and the second fills the remainder. Third, pros and cons for this specific case. Flexbox is less code, handles wrapping and variable content flow naturally, and is conceptually simpler for a single axis layout. Grid gives explicit column tracks, cleaner gap support without margin hacks, and makes future layout changes like adding a header row easier, but it introduces a second dimension you are not actually using. Fourth, mention real behavior differences. In Flexbox, the main area can shrink below its content size unless you set min-width: 0, which surprises people. Grid tracks respect their sizing more rigidly, so overflow behavior is more predictable.
The mistakes people make
Saying Grid is always the modern best practice and Flexbox is outdated. Using width percentages instead of flex or fr units. Forgetting that Flexbox items have a default min-width: auto that can prevent shrinking. Claiming Grid requires more markup; it does not. Ignoring gap handling, which in Grid is native and in Flexbox historically required margins.
What usually comes next
How would you handle a responsive breakpoint where the sidebar collapses or stacks? What happens if the main content has a very wide table or image? How do you add consistent spacing between the two areas without margin hacks? Have you used subgrid or container queries to solve similar problems?
A concrete example
Imagine a dashboard at 1440px viewport width. With Flexbox, the sidebar stays at 250px and the main area is 1190px. If the user opens a wide data table inside main, Flexbox may refuse to shrink the main area below the table width and push the sidebar off screen unless you explicitly set min-width: 0 on the main area. With Grid, the 1fr track will stay at 1190px and overflow the table inside it rather than breaking the outer layout, because the grid track itself is rigidly sized.
Interview question
In a Flexbox sidebar layout, why does a wide table in the main area sometimes push the fixed sidebar off screen?
- a.Flexbox cannot constrain two-dimensional layouts without switching to CSS Grid
- b.The flex: 1 declaration forces the main area to expand beyond the container bounds
- c.The sidebar should use a percentage width instead of flex: none to remain stable
- d.The main area defaults to min-width: auto and refuses to shrink below the table widthCorrect
Why? this is the answer
The correct answer is B because Flexbox items default to min-width: auto, which prevents the main area from shrinking below its content size and pushes the sidebar off-screen. Option A is tempting but wrong because a single-row layout is exactly what Flexbox is designed for, and claiming Grid is always superior is a common red flag.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.
See open roles