伙计们,我是顺风的新手,并试图在表行之间添加空间。
<table className="table-auto w-full shadow-md mt-5 rounded">
<thead className="bg-base-200 text-left text-gray-700 tracking-wider">
<tr>
<th className="p-4 ">Chapter Number</th>
<th className="p-4 ">Chapter Name</th>
<th className="p-4 ">Added at</th>
<th className="p-4 ">Status</th>
</tr>
</thead>
<tbody>
{chapters.map((chapter) => (
<tr className="bg-card mt-6 rounded" key={chapter.chapterNumber}>
<td className="p-4">{chapter.chapterNumber}</td>
<td className="p-4">{chapter.chapterName}</td>
<td className="p-4">{chapter.addedAt}</td>
<td className="p-4">{!chapter.published && 'Not published'}</td>
</tr>
))}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
这不会增加表行之间的空间。mt-6所以,我在每一行都尝试过。它没有任何作用。
我看到过类似的问题并使用了 此处的答案,并添加了border-spacing和border-seperate。
所以,现在我的表行有这些类。
<table className="table-auto w-full shadow-md mt-5 border-spacing-2 border-separate rounded">
Run Code Online (Sandbox Code Playgroud)
我不明白为什么表行会这样表现并且不采用marginwith mt-6。
但如果我用 div 替换行,它会应用边距顶部。例如:
<div className="">
<th className="p-4 ">Chapter Number</th>
<th className="p-4 ">Chapter Name</th>
<th className="p-4 ">Added at</th>
<th className="p-4 ">Status</th>
</div>
<div className="mt-6 bg-card">
<th className="p-4 ">1</th>
<th className="p-4 ">Chapter Name</th>
<th className="p-4 ">04/2/2022</th>
<th className="p-4 ">Not published</th>
</div>
<div className="mt-6 bg-card">
<th className="p-4 ">1</th>
<th className="p-4 ">Chapter Name</th>
<th className="p-4 ">04/2/2022</th>
<th className="p-4 ">Not published</th>
</div>
Run Code Online (Sandbox Code Playgroud)
首先,您需要使用table标签上的Tailwind border-separate 属性分割边框,然后添加其中:y是轴,number 是行之间的高度。border-spacing-y-3
用于控制表格边框之间的间距的实用程序。Tailwind 文档
<script src="https://cdn.tailwindcss.com"></script>
<table class="table-auto w-full shadow-md mt-5 rounded bg-black border-separate border-spacing-y-3">
<thead class="text-left text-gray-500 tracking-wider">
<tr>
<th class="p-4">Chapter Number</th>
<th class="p-4">Chapter Name</th>
<th class="p-4">Added at</th>
<th class="p-4">Status</th>
</tr>
</thead>
<tbody class="">
<tr class="bg-card rounded text-gray-200 bg-neutral-900">
<td class="p-4">60001</td>
<td class="p-4"></td>
<td class="p-4">6/21/2022</td>
<td class="p-4">Not published</td>
</tr>
<tr class="bg-card rounded text-gray-200 bg-neutral-900">
<td class="p-4">60001</td>
<td class="p-4"></td>
<td class="p-4">6/21/2022</td>
<td class="p-4">Not published</td>
</tr>
</tbody>
</table>Run Code Online (Sandbox Code Playgroud)