粘滞导航组件
一个极简且响应迅速的博客粘性导航栏,具有充满活力的配色方案。它支持深色模式,并具有简单、干净的布局,左侧是 “Blog Title” ,右侧是导航链接。当用户滚动时,导航栏会粘在视区的顶部。
HTML 代码
<nav class="bg-gradient-to-r from-teal-400 to-blue-500 dark:from-gray-800 dark:to-gray-900 p-4 shadow-md sticky top-0 z-50">
<div class="container mx-auto flex justify-between items-center">
<!-- Blog Title -->
<a href="#" class="text-white text-2xl font-bold dark:text-gray-100">Blog Title</a>
<!-- Navigation Links -->
<div class="hidden md:flex space-x-6">
<a href="#" class="text-white hover:text-gray-100 dark:text-gray-300 dark:hover:text-white transition duration-300 ease-in-out">Home</a>
<a href="#" class="text-white hover:text-gray-100 dark:text-gray-300 dark:hover:text-white transition duration-300 ease-in-out">Categories</a>
<a href="#" class="text-white hover:text-gray-100 dark:text-gray-300 dark:hover:text-white transition duration-300 ease-in-out">About</a>
<a href="#" class="text-white hover:text-gray-100 dark:text-gray-300 dark:hover:text-white transition duration-300 ease-in-out">Contact</a>
</div>
<!-- Mobile Menu Button (Hamburger) -->
<div class="md:hidden">
<button class="text-white focus:outline-none">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
</div>
</div>
<!-- Mobile Menu (Hidden by default, can be shown with JS) -->
<div class="md:hidden mt-4 space-y-2">
<!-- Hidden for this pure HTML example as JS is not allowed -->
</div>
</nav>