Creating Navigation with CSS

CSS navigation bars are essential website components. They can be horizontal or vertical, fixed or static.

Navigation Patterns

Horizontal nav uses Flexbox or inline-block.

Vertical nav uses block-level list items.

Fixed navigation stays on screen during scroll.

Sticky navigation becomes fixed after scrolling.

Dropdown menus use absolute positioning.

/* Horizontal Navigation */
nav {
  background-color: #333;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}

nav li {
  margin: 0;
}

nav a {
  display: block;
  padding: 15px 20px;
  color: white;
  text-decoration: none;
  transition: background-color 0.3s;
}

nav a:hover {
  background-color: #555;
}

/* Fixed navigation */
.fixed-nav {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 1000;
}

/* Sticky navigation */
.sticky-nav {
  position: sticky;
  top: 0;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}