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

How does flex-basis differ from width?

Difference Between flex-basis and width in Flexbox

flex-basis and width may seem similar, but they serve different purposes in Flexbox layouts. flex-basis defines the initial size of a flex item before distributing remaining space, while width is the standard CSS width property.

Key Differences
  1. 1

    flex-basis: Sets the starting size of a flex item along the main axis before flex-grow and flex-shrink are applied. Can be auto, a length, or a percentage.

  2. 2

    width: Sets the fixed width of an element regardless of Flexbox behavior. It does not account for available space distribution automatically.

  3. 3

    Priority: If flex-basis is specified, it overrides width in determining the initial main size of a flex item.

  4. 4

    Flexibility: flex-basis works with flex-grow and flex-shrink to create flexible layouts, while width alone creates a fixed-size element unless combined with Flexbox properties.

Example: flex-basis vs width

In this example, the first item (flex-basis) starts at 200px but can grow to fill available space due to flex-grow: 1. The second item (width) remains fixed at 200px initially, but flex-grow: 1 may cause it to behave differently depending on browser interpretation.

Difficulty: 6/10
Topics: flex-basis, layout behavior, box-sizing interaction

Scenario Questions

0-2 years experience
  1. 1

    You're building a card grid with three items in a row, and you set width: 300px on each, but they're wrapping unexpectedly — what’s the most likely cause, and how would you fix it using flex-basis?

  2. 2

    If you set flex-basis: 200px on a flex item but its content is only 100px wide, will it shrink? Why or why not?

  3. 3

    A teammate says 'I set width: 50% on my flex item but it's not taking half the container' — what would you check first?

2-5 years experience
  1. 1

    Our responsive product grid breaks on mobile — items overflow when flex-basis is set to auto, but work fine with width: 100%. What’s the root cause, and how would you debug this without breaking desktop layout?

  2. 2

    A modal component uses flexbox for its content area, but when you add a long heading, the layout collapses. You tried setting width: 100%, but it didn’t help. What’s the real issue, and how would you fix it using flex-basis correctly?

  3. 3

    We have a dynamic sidebar that should be 250px wide on desktop but collapse to auto on mobile. We tried width: 250px and flex: 1 on the main content, but the sidebar still shrinks too much. What’s the right way to structure this with flex-basis?

5-8 years experience
  1. 1

    We’re migrating a legacy layout from float-based grids to flexbox, and some components are rendering inconsistently across browsers. The issue only appears when flex-basis is auto and content is dynamic — how would you design a robust, cross-browser solution that avoids layout thrashing?

  2. 2

    Our design system has a reusable flex-based card component that needs to support both fixed-width and fluid layouts. How would you architect the CSS so that flex-basis and width interact predictably across different usage contexts without requiring consumers to override styles?

  3. 3

    In a high-performance dashboard with 50+ dynamic flex items, we’re seeing jank on scroll. After profiling, layout recalculations are the bottleneck. How would you optimize flex-basis usage to reduce reflow cost without sacrificing layout flexibility?

8+ years experience
  1. 1

    We’re designing a cross-platform UI framework that must support both flexbox and grid layouts interchangeably. How would you define a consistent API for sizing primitives that abstracts the difference between flex-basis and width without leaking implementation details to component consumers?

  2. 2

    Our legacy CSS architecture has hundreds of components mixing width, min-width, and flex-basis inconsistently — leading to unpredictable layouts across teams. How would you design a migration strategy and linting rules to enforce a scalable, maintainable sizing pattern across the organization?

  3. 3

    We’re evaluating whether to standardize on flex-basis over width for all new components. What are the long-term maintenance, performance, and accessibility tradeoffs of this decision, and how would you communicate it to engineering and design leadership?

Follow-up Questions

  • What happens if you set both flex-basis and width on the same flex item?
  • How does flex-basis behave differently when flex-wrap is enabled?
  • Can you explain why a flex item might ignore its width value in a row container?