Problem: Dynamically Even-Spacing and Centering of N Items

hard
40 min
Try to distribute an unknown number of menu items evenly and center them using Flexbox without relying on hard-coded spacing.

Problem description

A <nav class="menu"> contains an unknown number of <a> items. The task is to ensure each link receives equal horizontal space and the entire group is centered horizontally without hard-coded margins or nth-child selectors.

Goal

Ensure each link shares equal space and the collection of links is centered in the navbar.

Constraints

Use only CSS on the existing elements; do not alter HTML structure or add JavaScript.

Sample visual output

Here’s what the output would look like:

Good luck trying the problem! If you’re unsure how to proceed, check the Solution.

Problem: Dynamically Even-Spacing and Centering of N Items

hard
40 min
Try to distribute an unknown number of menu items evenly and center them using Flexbox without relying on hard-coded spacing.

Problem description

A <nav class="menu"> contains an unknown number of <a> items. The task is to ensure each link receives equal horizontal space and the entire group is centered horizontally without hard-coded margins or nth-child selectors.

Goal

Ensure each link shares equal space and the collection of links is centered in the navbar.

Constraints

Use only CSS on the existing elements; do not alter HTML structure or add JavaScript.

Sample visual output

Here’s what the output would look like:

Good luck trying the problem! If you’re unsure how to proceed, check the Solution.