Questions
22 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?
22 / 51

What are the three components of the flex shorthand property?

Understanding the flex Shorthand Property in Flexbox

The flex shorthand property in CSS defines how a flex item grows, shrinks, and sets its base size within a flex container. It combines three individual properties — flex-grow, flex-shrink, and flex-basis — into a single, concise declaration.

Syntax
  1. 1

    flex: <flex-grow> <flex-shrink> <flex-basis>;

  2. 2

    Each value is optional, and omitted values fall back to defaults.

Components of the flex Shorthand
  1. 1

    flex-grow: Defines how much a flex item will grow relative to the rest when space is available (default: 0).

  2. 2

    flex-shrink: Defines how much a flex item will shrink relative to others when space is limited (default: 1).

  3. 3

    flex-basis: Defines the initial size of the item before space distribution (default: auto).

Example: Using the flex Shorthand

In this example, Item 2 grows twice as fast as Items 1 and 3 because its flex-grow value is 2. All items start with a base width of 150px and shrink equally if necessary.

Common Shorthand Values
  1. 1

    flex: 1; → Equivalent to flex: 1 1 0; (items grow and shrink equally).

  2. 2

    flex: auto; → Equivalent to flex: 1 1 auto;.

  3. 3

    flex: none; → Equivalent to flex: 0 0 auto; (fixed size, no growth or shrink).

  4. 4

    flex: initial; → Equivalent to flex: 0 1 auto; (default behavior).

Best Practices
  1. 1

    Use flex: 1 to evenly distribute available space among items.

  2. 2

    Use flex: none for fixed-size elements like buttons or logos.

  3. 3

    Combine flex-grow and flex-basis strategically for responsive layouts.

  4. 4

    Avoid mixing width and flex properties unless necessary for layout control.

The flex shorthand lets you control item growth, shrinkage, and base size in one line. Understanding flex-grow, flex-shrink, and flex-basis helps create flexible, responsive layouts efficiently.

Difficulty: 3/10
Topics: flex-shorthand, layout alignment, responsive design

Scenario Questions

0-2 years experience
  1. 1

    You're building a two-column layout where the left column should take up 70% of the width and the right column 30%. You set flex: 7 3 on the left and flex: 3 7 on the right, but both columns are equal width. What’s wrong?

  2. 2

    A button inside a flex container is overflowing its parent. You set flex: 1 on the button. Why isn’t it shrinking to fit, and how would you fix it?

2-5 years experience
  1. 1

    A responsive card grid breaks on mobile: items wrap but stretch too wide. You used flex: 1 1 100% on each card. What’s the likely issue, and how would you adjust the flex values to fix it without changing the HTML?

  2. 2

    Your team’s header component uses flex: 1 on the title and flex: 0 0 auto on the buttons. On tablets, the title gets cut off. How would you diagnose and fix this without hardcoding widths?

5-8 years experience
  1. 1

    You’re designing a dynamic dashboard with collapsible panels. Each panel uses flex: 1 1 auto. When users collapse panels, the remaining ones don’t redistribute space smoothly. How would you redesign the flex configuration to handle dynamic sizing without layout thrashing?

  2. 2

    A legacy component uses flex: 1 on all children in a row. When one child has a very long text node, it breaks the layout on small screens. How would you refactor this to be resilient without changing the component’s structure?

8+ years experience
  1. 1

    Your company’s design system uses flex: 1 across hundreds of components. As the UI scales, performance degrades on low-end devices due to constant flex recalculations. How would you architect a migration strategy to reduce layout thrash while maintaining backward compatibility?

  2. 2

    You’re leading a cross-team effort to unify layout patterns. One team uses flex: 1 1 0%, another uses flex: 1 1 auto. How do you evaluate which approach is more sustainable long-term for a global component library, and how would you enforce consistency without breaking existing features?

Follow-up Questions

  • What happens if you set flex: 1 1 auto on an element with no explicit width?
  • How would you debug a flex item that’s not shrinking as expected?
  • Why might flex: 1 not work the same as flex: 1 1 0?