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

How would you create a horizontal navigation bar using Flexbox?

Creating a Horizontal Navigation Bar with Flexbox

Flexbox makes it easy to create a horizontal navigation bar by aligning items in a row and controlling spacing and alignment.

Key Steps
  1. 1

    Set the container's display to flex and use flex-direction: row (default) for horizontal layout.

  2. 2

    Use justify-content to distribute items along the main axis (e.g., space-between or space-around).

  3. 3

    Use align-items to vertically align navigation items within the bar (e.g., center).

  4. 4

    Apply gap to maintain consistent spacing between items without using margins.

  5. 5

    Optionally, style links for hover effects, padding, and background colors for a polished look.

Example: Horizontal Navigation Bar

In this example, the .navbar container uses Flexbox to arrange links horizontally with equal spacing. Hover effects and padding enhance usability and visual appeal.

Difficulty: 3/10
Topics: Flexbox layout, horizontal alignment, responsive navigation

Scenario Questions

0-2 years experience
  1. 1

    How would you create a horizontal navigation bar with five links that are evenly spaced and vertically centered in the header using only Flexbox?

  2. 2

    What happens if you forget to set flex-direction on the container? Can you explain why the links stack vertically?

  3. 3

    You’ve built a nav bar but the items are overflowing the container — what’s the most likely cause and how do you fix it?

2-5 years experience
  1. 1

    Our navigation bar breaks on tablets — the links wrap and look messy. How would you debug and fix this without adding a media query?

  2. 2

    A designer says the nav should collapse into a hamburger menu on mobile, but we need to keep the same HTML structure. How would you adapt the Flexbox layout to support both states?

  3. 3

    The nav bar works fine in Chrome but misaligns in Safari — what Flexbox quirks might be causing this, and how would you investigate?

5-8 years experience
  1. 1

    We’re building a global navigation component used across 50+ product pages with dynamic content — how would you design the Flexbox structure to handle variable link counts, long text, and accessibility without layout shifts?

  2. 2

    Our nav bar performance is lagging on low-end devices during scroll. Could Flexbox be contributing? What optimizations or alternatives would you consider?

  3. 3

    A legacy component uses floats for horizontal nav. You’re tasked with migrating it to Flexbox without breaking existing CSS overrides. How would you approach this safely?

8+ years experience
  1. 1

    We’re standardizing our design system’s navigation component across 10 engineering teams. How would you architect the Flexbox-based nav to support theming, internationalization, and future accessibility requirements without forcing a full rewrite later?

  2. 2

    Our nav bar is used in both web and embedded WebView contexts — the latter has inconsistent Flexbox support. How would you design a fallback strategy that balances consistency, maintenance cost, and user experience?

  3. 3

    A major partner requires our nav to work in a legacy browser that only supports Flexbox 2012 spec. How would you justify the technical debt vs. the cost of a polyfill or alternative layout, and how would you document the long-term exit strategy?

Follow-up Questions

  • What happens if one link has much longer text than the others?
  • How would you make this work on mobile without changing the HTML?
  • Why not use grid instead?