材料设计搜索框
一个受材料设计原则启发的搜索框组件,使用 Tailwind CSS 构建。它具有响应式行为,能够适应容器宽度,通过悬停和聚焦阴影过渡(深度效果)提供视觉反馈,并全面支持黑暗主题。该组件包括一个领先的搜索图标,并确保干净、现代的美学。仅使用 CSS 实现。由于其 `w-full` 特性,非常适合嵌入各种布局。为确保无障碍,确保将 `input` 元素与相应的 `<label>` 配对,或提供描述性的 `aria-label` 。
HTML 代码
<!-- Component Start: Material Design Search Box -->
<div class="flex items-center w-full bg-white dark:bg-gray-700 shadow-md hover:shadow-lg focus-within:shadow-lg transition-shadow duration-200 ease-in-out rounded-lg">
<div class="pl-4 pr-2 py-3">
<svg class="h-5 w-5 text-gray-500 dark:text-gray-400 pointer-events-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
</svg>
</div>
<input
type="search"
name="search_query"
id="material_search_box_input"
placeholder="Search..."
aria-label="Search"
class="
appearance-none
w-full h-12
pl-0 pr-4 py-3
text-base text-gray-900 dark:text-gray-100
bg-transparent
focus:outline-none
placeholder-gray-500 dark:placeholder-gray-400
"
/>
</div>
<!-- Component End -->