如何使用 Flowbite 构建 Tailwind CSS 时间线组件
我一直在使用 Tailwind CSS 来构建网站,实用程序类的强大功能加上Flowbite中的组件使它变得更加轻松和有趣!
我已经开始了一个关于如何使用 Tailwind CSS 中的类创建一些最常用的 UI 组件的教程系列,今天我想向您展示如何构建一个时间线组件。
这是它的外观预览:
[
](https://res.cloudinary.com/practicaldev/image/fetch/s--fscOYuI2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to -uploads.s3.amazonaws.com/uploads/articles/4sx70hujpy6ouofl56yp.png)
让我们开始吧!
Tailwind CSS 时间线
首先,我们需要设置基本的 HTML 标记。我们将使用<ol>元素。
<ol>
<li>
<time>February 2022</time>
<h3>Application UI code in Tailwind CSS</h3>
<p>Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order E-commerce & Marketing pages.</p>
</li>
<li>
<time>March 2022</time>
<h3>Marketing UI design in Figma</h3>
<p>All of the pages and components are first designed in Figma and we keep a parity between the two versions even as we update the project.</p>
</li>
<li>
<time>April 2022</time>
<h3>E-Commerce UI code in Tailwind CSS</h3>
<p>Get started with dozens of web components and interactive elements built on top of Tailwind CSS.</p>
</li>
</ol>
进入全屏模式 退出全屏模式
惊人的!现在让我们设置时间轴内元素的间距、排版和颜色。
<ol class="relative border-l border-gray-200">
<li class="mb-10 ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white"></div>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Application UI code in Tailwind CSS</h3>
<p class="mb-4 text-base font-normal text-gray-500">Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order E-commerce & Marketing pages.</p>
</li>
<li class="mb-10 ml-4">
<time class="mb-1 text-sm font-normal leading-none text-gray-400">March 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Marketing UI design in Figma</h3>
<p class="text-base font-normal text-gray-500">All of the pages and components are first designed in Figma and we keep a parity between the two versions even as we update the project.</p>
</li>
<li class="ml-4">
<time class="mb-1 text-sm font-normal leading-none text-gray-400">April 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">E-Commerce UI code in Tailwind CSS</h3>
<p class="text-base font-normal text-gray-500">Get started with dozens of web components and interactive elements built on top of Tailwind CSS.</p>
</li>
</ol>
进入全屏模式 退出全屏模式
已经看起来好多了。现在让我们添加点和 CTA 按钮链接。
<ol class="relative border-l border-gray-200">
<li class="mb-10 ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400">February 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Application UI code in Tailwind CSS</h3>
<p class="mb-4 text-base font-normal text-gray-500">Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order E-commerce & Marketing pages.</p>
<a href="#" class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">Learn more <svg class="w-3 h-3 ml-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M12.293 5.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></a>
</li>
<li class="mb-10 ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400">March 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Marketing UI design in Figma</h3>
<p class="text-base font-normal text-gray-500">All of the pages and components are first designed in Figma and we keep a parity between the two versions even as we update the project.</p>
</li>
<li class="ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400">April 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">E-Commerce UI code in Tailwind CSS</h3>
<p class="text-base font-normal text-gray-500">Get started with dozens of web components and interactive elements built on top of Tailwind CSS.</p>
</li>
</ol>
进入全屏模式 退出全屏模式
很好!时间线组件现在应该看起来像预览图片中的样子。
最后,让我们也为暗模式应用一些暗变体类。
注意:查看本教程,了解如何使用 Tailwind CSS 和 Flowbite](https://flowbite.com/docs/customize/dark-mode/)设置[暗模式。
<ol class="relative border-l border-gray-200 dark:border-gray-700">
<li class="mb-10 ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white dark:border-gray-900 dark:bg-gray-700"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400 dark:text-gray-500">February 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Application UI code in Tailwind CSS</h3>
<p class="mb-4 text-base font-normal text-gray-500 dark:text-gray-400">Get access to over 20+ pages including a dashboard layout, charts, kanban board, calendar, and pre-order E-commerce & Marketing pages.</p>
<a href="#" class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">Learn more <svg class="w-3 h-3 ml-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M12.293 5.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></a>
</li>
<li class="mb-10 ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white dark:border-gray-900 dark:bg-gray-700"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400 dark:text-gray-500">March 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Marketing UI design in Figma</h3>
<p class="text-base font-normal text-gray-500 dark:text-gray-400">All of the pages and components are first designed in Figma and we keep a parity between the two versions even as we update the project.</p>
</li>
<li class="ml-4">
<div class="absolute w-3 h-3 bg-gray-200 rounded-full -left-1.5 border border-white dark:border-gray-900 dark:bg-gray-700"></div>
<time class="mb-1 text-sm font-normal leading-none text-gray-400 dark:text-gray-500">April 2022</time>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">E-Commerce UI code in Tailwind CSS</h3>
<p class="text-base font-normal text-gray-500 dark:text-gray-400">Get started with dozens of web components and interactive elements built on top of Tailwind CSS.</p>
</li>
</ol>
进入全屏模式 退出全屏模式
时间线在暗模式下应如下所示:
[
](https://res.cloudinary.com/practicaldev/image/fetch/s--D_nce_bi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev -to-uploads.s3.amazonaws.com/uploads/articles/czslesbdmtnhivninv1l.png)
这个Tailwind CSS 时间线组件是 Tailwind CSS 组件开源库的一部分,称为 Flowbite。
您可以找到更多时间线组件样式和变体,以及一整套其他元素,例如按钮、下拉菜单、模式、工具提示等。
👉Flowbite - Tailwind CSS 时间线
📚Flowbite - Tailwind CSS 组件
更多推荐


所有评论(0)