Skip to main content

Command Palette

Search for a command to run...

Responsive Navbar & Hero Section (Flexbox + Grid + Basics That Actually Matter)

Updated
4 min read
Responsive Navbar & Hero Section (Flexbox + Grid + Basics That Actually Matter)
S
Self-learner focused on algorithms and human-centric, scalable technology

Most beginners jump into frameworks too early.

This project is intentionally simple:
a Navbar + Hero section using only HTML, CSS, and minimal JavaScript.

The goal wasn’t just to “make it work” , it was to understand:

  • Flexbox (with simple one grid layout)

  • Spacing

  • Alignment

  • Responsiveness

  • Small UI details

Desktop

Mobile

Why This Project Matters

This is the kind of UI you’ll build over and over again in real projects.

If you can’t confidently build:

  • a responsive navbar

  • a clean hero section

  • proper spacing and alignment

…then adding React or Tailwind won’t fix that.

Fexbox → One-dimensional layout

Used in:

  • Navbar
  • Buttons
  • Horizontal/vertical alignment

Example:

.navbar-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

Why Flexbox here?

  • You’re aligning items in a single row

  • You need spacing between logo and links

  • You want easy vertical centering

Grid → Two-dimensional layout

Used in:

  • Hero section
.hero-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

Why Grid?

  • You’re managing content + image

  • You want structured columns

  • Easier to switch to 1 column on mobile

Spacing System (This Changes Everything)

Instead of random values like margin: 23px, I used a spacing scale:

:root {
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
}

Then:

.hero-buttons {
  gap: var(--spacing-md);
}

Why this matters:

  • Consistency across UI

  • Easier to scale later

  • Feels more “designed” instead of random

Alignment (The Silent Skill)

Alignment is where most beginner UIs break.

Key patterns used:

Centering content vertically

.hero {
  display: flex;
  align-items: center;
  justify-content: center;
}

Aligning navbar items

.nav-links {
  display: flex;
  align-items: center;
}

Controlling max width

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
}

This prevents content from stretching too wide.

Responsive Design (Mobile First Thinking)

Instead of fixing desktop → breaking mobile, I handled mobile intentionally.

Example:

@media (max-width: 480px) {
  .hero-container {
    grid-template-columns: 1fr;
  }
}

What changes on mobile:

  • Grid → single column

  • Buttons stack vertically

  • Navbar becomes hamburger menu

Hamburger Menu (Minimal JavaScript)

The menu is mostly CSS-driven using a checkbox trick.

JavaScript only handles:

  • closing menu when clicking a link

  • closing when clicking outside

navLinks.forEach(link => {
  link.addEventListener('click', () => {
    menuToggle.checked = false;
  });
});

This keeps things lightweight.

Basic Animations (Small but Important)

Nothing complex — just subtle motion.

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

Fade + move up

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
}

Why animations matter:

  • Makes UI feel alive

  • Guides user attention

  • Improves perceived quality

Design System (Early Discipline)

Instead of hardcoding colors everywhere:

:root {
  --color-primary: #1e1b4b;
  --color-accent: #4f46e5;
}

Benefits:

  • Easy theme changes

  • Cleaner code

  • Scalable for larger projects

Accessibility Basics Included

Even in a small project:

  • aria-label for navigation

  • :focus-visible for keyboard users

  • prefers-reduced-motion support

Example:

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
  }
}

What I Took Away

This project looks simple but it builds core instincts:

  • When to use Flexbox vs Grid

  • How to control spacing properly

  • How to think in responsive layouts

  • How small details improve UI quality

What I’ll Improve Next

  • Add dark mode

  • Turn this into reusable components

  • Convert to React / Next.js


Final Thought

Frameworks don’t replace fundamentals.

If you can build this cleanly from scratch,
you’re already ahead of most beginners.

HTML & CSS Mastery Series (Project-Based)

Part 1 of 1

In this series, I master HTML & CSS by building real-world UI components from scratch — no frameworks, just fundamentals. Each project focuses on layout systems (Flexbox & Grid), spacing, alignment, responsiveness, and clean, scalable CSS. GitHub Repo: https://github.com/ysdesilva21/html-css-mini-projects

More from this blog

S

Sanju De Silva | Developer Blog

2 posts

I’m Sanju De Silva, a developer focused on building web applications across the frontend and backend. This blog documents my journey as I move from frontend fundamentals into fullstack development. I share what I build, what I learn, and the decisions behind my projects.