Questions
24 of 51
1What is Flexbox in CSS?
2What problem does Flexbox solve compared to traditional layouts like float or inline-block?
3How do you create a flex container?
4What are the main and cross axes in Flexbox?
5What does the display: flex property do?
6What is the difference between display: flex and display: inline-flex?
7What are flex items?
8How do you change the direction of items in a flex container?
9What does flex-direction: row do?
10What does flex-direction: column do?
11What is the purpose of the justify-content property?
12What does the align-items property control?
13What are the possible values of align-content?
14What is the difference between align-items and align-content?
15What is the use of the flex-wrap property?
16How can you make flex items wrap onto multiple lines?
17What does the flex-flow shorthand property do?
18How does the order property affect flex items?
19How does the align-self property work?
20How do you vertically center content using Flexbox?
21What does the flex shorthand property represent?
22What are the three components of the flex shorthand property?
23What is the default value of the flex property?
24How do flex-grow, flex-shrink, and flex-basis work individually?
25What is the difference between flex: 1 and flex: auto?
26What is the difference between flex: 1 and flex: auto?
27What is the purpose of the gap property in Flexbox?
28How does Flexbox handle overflowing content?
29What’s the difference between justify-content: space-around and space-between?
30How does Flexbox handle fixed and flexible widths together?
31Can Flexbox be nested?
32How is Flexbox different from CSS Grid?
33When would you use Flexbox instead of Grid?
34Can you use Flexbox and Grid together in the same layout?
35How does Flexbox differ from traditional float-based layouts?
36Does Flexbox affect the box model or positioning of elements?
37How does Flexbox handle min-width and max-width constraints?
38How do flex items align when the container has align-items: stretch?
39What is the difference between flex: 0 1 auto and flex: 1 0 auto?
40How does flex-basis differ from width?
41How do you prevent a flex item from shrinking?
42How would you create a horizontal navigation bar using Flexbox?
43How do you center a div both horizontally and vertically using Flexbox?
44How can you make a responsive layout using Flexbox?
45How can you make one flex item take up the remaining space in a container?
46How do you create equal-height columns using Flexbox?
47How can you align the last flex item to the right side of the container?
48How can you reorder items visually using Flexbox without changing the HTML structure?
49How can you make items stack vertically on mobile and horizontally on desktop using Flexbox?
50How do you prevent an element from wrapping in a flex container?
51How can you align items to the bottom of a container using Flexbox?
24 / 51

How do flex-grow, flex-shrink, and flex-basis work individually?

Understanding flex-grow, flex-shrink, and flex-basis

The three components of the flex shorthand property each control a different aspect of a flex item's behavior within a flex container.

Individual Behavior
  1. 1

    flex-grow: Determines how much a flex item can grow relative to other items when there is extra space. A value of 0 means the item will not grow.

  2. 2

    flex-shrink: Determines how much a flex item can shrink relative to other items when space is limited. A value of 1 means the item can shrink if needed.

  3. 3

    flex-basis: Sets the initial main size of the item before distributing space. It can be a length, percentage, or auto (default), which uses the item's content size.

Example: Individual flex Properties

In this example, Item 2 grows faster than Items 1 and 3 due to a higher flex-grow. Item 3 can shrink more than others because of a higher flex-shrink. Each item starts with its specified flex-basis as the initial size.

Difficulty: 6/10
Topics: flex-grow, flex-shrink, flex-basis

Scenario Questions

0-2 years experience
  1. 1

    You have a flex container with three items: one with flex: 1, another with flex: 2, and a third with flex: 0. If the container is 600px wide and each item’s content is 100px, how wide will each item be? Walk me through your reasoning.

  2. 2

    If I set flex-basis: 200px on an item but the container is only 300px wide with two other items, what happens? What if I also set flex-shrink: 0?

  3. 3

    I have a row of buttons in a flex container, and one button is way wider than the others even though they all have the same flex: 1. What’s the most likely cause?

2-5 years experience
  1. 1

    Our mobile nav bar has three items that collapse weirdly on small screens — one gets squished to 0px while others stay readable. I set flex: 1 on all, but it’s still breaking. What could be going wrong, and how would you fix it?

  2. 2

    A card component with dynamic content is overflowing its container on desktop but looks fine on mobile. The parent uses flexbox. How would you diagnose whether flex-grow, flex-shrink, or flex-basis is the culprit?

  3. 3

    We’re building a responsive dashboard with a sidebar and main content area. The sidebar should be 250px wide on desktop but shrink to 80px on tablet. How would you use flex properties to make this work without media queries for sizing?

5-8 years experience
  1. 1

    We have a legacy layout using flexbox for a multi-column form that breaks unpredictably when dynamic form fields are added. Users report some inputs disappearing or overflowing. How would you audit and redesign this to be robust across content variations and screen sizes?

  2. 2

    A component library uses flexbox for card grids, but performance degrades on low-end devices when content is long. How might flex-shrink and flex-basis contribute to layout thrashing, and what optimizations would you propose?

  3. 3

    We’re migrating from float-based layouts to flexbox for a high-traffic e-commerce product grid. Some product cards have variable-height images and titles. How do you ensure consistent baseline alignment and avoid layout shifts without hard-coding heights?

8+ years experience
  1. 1

    Our design system uses flexbox for all layout primitives, but we’re seeing inconsistent behavior across teams due to implicit defaults. How would you enforce consistent flex behavior at the architecture level without over-constraining designers?

  2. 2

    We’re considering replacing flexbox with CSS Grid for our main layout system due to scalability concerns. What are the long-term maintenance tradeoffs between flexbox (with complex flex-grow/shrink rules) and grid for a global component library used by 50+ engineers?

  3. 3

    Legacy codebase has hundreds of flex containers with mixed flex: 1, flex: auto, and inline styles. We need to refactor for accessibility and performance. How would you prioritize which flex properties to standardize first, and how would you measure success?

Follow-up Questions

  • What happens if you set flex-basis to auto instead of a fixed value?
  • How would you debug a layout where items are shrinking unexpectedly despite having flex-grow set?
  • Why might flex-shrink: 0 not work as expected on a child with a min-width?