{
  "id": "sliding-indicator-nav",
  "name": "Sliding Hover Nav",
  "category": "navigation",
  "tags": [
    "nav",
    "has",
    "indicator",
    "hover",
    "slide",
    "highlight"
  ],
  "description": "Nav links with one highlight that slides to whichever link you hover, using :has(). No JavaScript.",
  "url": "https://copy-css.com/snippets/sliding-indicator-nav",
  "markdown": "https://copy-css.com/snippets/sliding-indicator-nav.md",
  "html": "<nav class=\"slide-nav\" aria-label=\"Main\">\n  <a href=\"#\" aria-current=\"page\">Home</a>\n  <a href=\"#\">Work</a>\n  <a href=\"#\">Blog</a>\n  <a href=\"#\">Shop</a>\n</nav>",
  "css": ".slide-nav {\n  --n: 4; /* number of links */\n  --i: 0; /* index of the highlighted link */\n  position: relative;\n  display: grid;\n  grid-auto-columns: 1fr;\n  grid-auto-flow: column;\n  padding: 4px;\n  border: 1px solid #e0e7ff;\n  border-radius: 12px;\n  font: 600 14px system-ui, sans-serif;\n}\n\n.slide-nav::before {\n  content: \"\";\n  position: absolute;\n  top: 4px;\n  bottom: 4px;\n  left: 4px;\n  width: calc((100% - 8px) / var(--n));\n  border-radius: 8px;\n  background: #e0e7ff;\n  transform: translateX(calc(var(--i) * 100%));\n  transition: transform 0.3s cubic-bezier(0.3, 0.7, 0.4, 1);\n}\n\n.slide-nav a {\n  position: relative;\n  padding: 9px 16px;\n  color: #64748b;\n  text-align: center;\n  text-decoration: none;\n  transition: color 0.2s ease;\n}\n\n.slide-nav a:hover,\n.slide-nav a:focus-visible,\n.slide-nav:not(:hover) a[aria-current] {\n  color: #3730a3;\n}\n\n.slide-nav a:focus-visible {\n  outline: 2px solid #6366f1;\n  border-radius: 8px;\n}\n\n/* Rest on the current page... */\n.slide-nav:has(> :nth-child(2)[aria-current]) { --i: 1; }\n.slide-nav:has(> :nth-child(3)[aria-current]) { --i: 2; }\n.slide-nav:has(> :nth-child(4)[aria-current]) { --i: 3; }\n\n/* ...and follow the pointer or keyboard focus */\n.slide-nav:has(> :nth-child(1):is(:hover, :focus-visible)) { --i: 0; }\n.slide-nav:has(> :nth-child(2):is(:hover, :focus-visible)) { --i: 1; }\n.slide-nav:has(> :nth-child(3):is(:hover, :focus-visible)) { --i: 2; }\n.slide-nav:has(> :nth-child(4):is(:hover, :focus-visible)) { --i: 3; }",
  "features": [
    "transitions",
    "transforms",
    "CSS Grid",
    "the :has() selector",
    "keyboard focus styles",
    "custom properties"
  ],
  "customProperties": [
    {
      "name": "--n",
      "value": "4"
    },
    {
      "name": "--i",
      "value": "0"
    }
  ]
}
