Tailwind CSS 是一个功能丰富的 CSS 框架,它提供了一系列的实用工具类,用于快速构建自定义设计。导航栏(Navbar)是网站或应用中常见的组件,用于提供导航链接。导航选项卡(Navigation Tabs)则是导航栏中的一种形式,允许用户在不同的内容区域之间切换。
导航选项卡通常有以下几种类型:
导航选项卡广泛应用于各种网站和应用的导航栏中,例如:
以下是一个使用 Tailwind CSS 创建带有导航选项卡的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tailwind CSS Navbar with Tabs</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<nav class="bg-white p-4 rounded shadow">
<div class="flex space-x-4">
<a href="#" class="text-blue-500 hover:text-blue-700">Home</a>
<a href="#" class="text-blue-500 hover:text-blue-700">About</a>
<div class="flex flex-col space-y-2">
<button class="text-blue-500 hover:text-blue-700 focus:outline-none" onclick="toggleTabs(event)">Services</button>
<div class="hidden space-y-2">
<a href="#" class="block text-sm text-blue-500 hover:text-blue-700">Web Development</a>
<a href="#" class="block text-sm text-blue-500 hover:text-blue-700">Mobile Development</a>
<a href="#" class="block text-sm text-blue-500 hover:text-blue-700">UI/UX Design</a>
</div>
</div>
<a href="#" class="text-blue-500 hover:text-blue-700">Contact</a>
</div>
</nav>
<script>
function toggleTabs(event) {
event.target.nextElementSibling.classList.toggle('hidden');
}
</script>
</body>
</html>
hidden
类的使用。通过以上步骤,你可以轻松地在 Tailwind CSS 中创建一个功能齐全的导航选项卡。
领取专属 10元无门槛券
手把手带您无忧上云