guys I am new to tailwind and trying to add space between table rows.
<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>
This does not add space between the table rows.
So,I have tried with mt-6 on each rows. It has no effect.
I have seen a similar question and used the answer here and have added border-spacing and border-seperate.
So, now my table row has these classes.
<table className="table-auto w-full shadow-md mt-5 border-spacing-2 border-separate rounded">
But this results in adding space around all the elements.
I do not understand why table row behaves this way and does not take the margin with mt-6.
But if i replace the rows with a div, it applies the margin top.
eg:
<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>
First you need to split the borders with Tailwind border-separate property on the table tag, then add border-spacing-y-3 where: y is the axis and number is the height between row.
Utilities for controlling the spacing between table borders. Tailwind documentation
<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>
Use border-seperate and border-spacing-y-4 to add vertical magin only.
<script src="https://cdn.tailwindcss.com"></script>
<div class="bg-black">
<table class="table-auto w-full shadow-md rounded border-separate border-spacing-y-4">
<thead class="text-white text-left bg-gray-900 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-stone-800 mt-6 text-white rounded" key={chapter.chapterNumber}>
<td class="p-4">{chapter.chapterNumber}</td>
<td class="p-4">{chapter.chapterName}</td>
<td class="p-4">{chapter.addedAt}</td>
<td class="p-4">{!chapter.published && 'Not published'}</td>
</tr>
<tr class="bg-stone-800 mt-6 text-white rounded" key={chapter.chapterNumber}>
<td class="p-4">{chapter.chapterNumber}</td>
<td class="p-4">{chapter.chapterName}</td>
<td class="p-4">{chapter.addedAt}</td>
<td class="p-4">{!chapter.published && 'Not published'}</td>
</tr>
<tr class="bg-stone-800 mt-6 text-white rounded" key={chapter.chapterNumber}>
<td class="p-4">{chapter.chapterNumber}</td>
<td class="p-4">{chapter.chapterName}</td>
<td class="p-4">{chapter.addedAt}</td>
<td class="p-4">{!chapter.published && 'Not published'}</td>
</tr>
<tr class="bg-stone-800 mt-6 text-white rounded" key={chapter.chapterNumber}>
<td class="p-4">{chapter.chapterNumber}</td>
<td class="p-4">{chapter.chapterName}</td>
<td class="p-4">{chapter.addedAt}</td>
<td class="p-4">{!chapter.published && 'Not published'}</td>
</tr>
</tbody>
</table>
</div>
Related
<table class="table">
<thead>
<tr class="d-flex">
<th class="col-0">JOB ID</th>
<th class="col-0">JOB STATUS</th>
<th class="col-0">USER</th>
<th class="col-0">BG TASK STATUS</th>
<th class="col-2">BG TASK RESULT</th>
<th class="col-0">BG TASK CREATED TIME</th>
<th class="col-0">BG TASK COMPLETED TIME</th>
<th class="col-0">DETAIL LOG LINK</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-0">15</td>
<td class="col-0">success</td>
<td class="col-0">None</td>
<td class="col-0"></td>
<td class="col-2"></td>
<td class="col-0"></td>
<td class="col-0"></td>
<td class="col-0">Job Details</td>
</tr>
</tbody>
</table>
Delete the className="d-flex" in tr tag
You can add the class text-justify to the table so that the text will be aligned to center
Using table-hover in Bootstrap and having a nested table, can I include the nested table in the hovering effect when I hover the row before nested?
I have searched if this has been asked before but no luck so far.
In my case since the second row is related to the nested table, I need the hover effect to be applied simultaneously in both the row and the nested table so the user can understand that they are related.
Below follows the code I am using:
<!DOCTYPE html>
<html>
<head></head>
<body>
<div id="div1" class="table-responsive">
<table id="1" class="table table-hover table-sm align-middle w-auto">
<thead class="align-middle">
<tr style="border-style: inherit; border-color: #000000; background-color: #f6f6f6;">
<th scope="col" style="text-align: center;">Col1</th>
<th scope="col" style="text-align: center;">Col2</th>
<th scope="col" style="text-align: center;">Col3</th>
<th scope="col" style="text-align: center;">Col4</th>
<th scope="col" style="text-align: center;">Col5</th>
<th scope="col" style="text-align: center;">Col6</th>
<th scope="col" style="text-align: center;">Col7</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1a</td>
<td style="text-align: center;">1b</td>
<td style="text-align: center;">1c</td>
<td style="text-align: center;">1d</td>
<td style="text-align: center;">1e</td>
<td style="text-align: center;">1f</td>
<td style="text-align: center;">1g</td>
</tr>
<tr>
<td style="text-align: center;">2a</td>
<td style="text-align: center;">2b</td>
<td style="text-align: center;">2c</td>
<td style="text-align: center;">2d</td>
<td style="text-align: center;">2e</td>
<td style="text-align: center;">2f</td>
<td style="text-align: center;">2g</td>
</tr>
<tr>
<td colspan="7">
<table class="table table-bordered table-striped table-sm align-middle mb-0 w-75" style="margin-left: auto; margin-right: auto;">
<thead class="align-middle">
<tr class="bg-info text-white" style="border-style: inherit; border-color: #000000;">
<th scope="col" style="text-align: center;">Col1-nested</th>
<th scope="col" style="text-align: center;">Col2-nested</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1a-nested</td>
<td style="text-align: center;">1b-nested</td>
</tr>
<tr>
<td style="text-align: center;">2a-nested</td>
<td style="text-align: center;">2b-nested</td>
</tr>
<tr>
<td style="text-align: center;">3a-nested</td>
<td style="text-align: center;">3b-nested</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
I have created it in JSFiddle so it is easier to understand how it looks like.
I am trying to add padding for table head and table rows in Tailwind based React App.
Here's my code:
import React from "react";
import "./styles.css";
import "./styles/tailwind-pre-build.css";
export default function App() {
return (
<table className="w-full px-2 rounded-t-md">
<thead className="text-white bg-blue-600 text-left border border-red-600 p-2">
<tr className="w-full p-2">
<th className="font-medium">App Name</th>
<th className="font-medium">Owner</th>
<th className="font-medium">Date Created</th>
<th className="font-medium">Scopes</th>
<th className="font-medium">Actions</th>
</tr>
</thead>
<tbody>
<tr className="p-2">
<td>Test App</td>
<td>Shivam Sahil</td>
<td>20 May 2022, 19:58 AM</td>
<td className="break-words">all.create all.update all.read</td>
<td>Edit</td>
</tr>
</tbody>
</table>
);
}
For some reason the padding doesn't seem to happen at all. I tried to inspect and check but even when adding padding in styles it won't show up, can someone help me understand what wrong am I doing here?
Here's the live sandbox:https://codesandbox.io/s/tailwind-css-and-react-forked-xwvdue?file=/src/App.js:0-884
You can adjust the padding inside the cells, so instead of <tr> you need set padding for all <th>, <td> tags.
<table className="w-full rounded-t-md">
<thead className="text-white bg-blue-600 text-left border border-red-600">
<tr className="w-full">
<th className="font-medium p-2">App Name</th>
<th className="font-medium p-2">Owner</th>
<th className="font-medium p-2">Date Created</th>
<th className="font-medium p-2">Scopes</th>
<th className="font-medium p-2">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td className="p-2">Test App</td>
<td className="p-2">Shivam Sahil</td>
<td className="p-2">20 May 2022, 19:58 AM</td>
<td className="break-words p-2">all.create all.update all.read</td>
<td className="p-2">Edit</td>
</tr>
</tbody>
</table>
OR
Instead of adding the p-2 class everywhere using the Tailwind Utilities, you will get the same result.
#tailwind base;
#tailwind components;
#tailwind utilities;
#layer utilities {
td,
th {
#apply p-2;
}
}
As using Bootstrap 4, I'm aware the .col-xs are dropped, instead of .col, I have tested on bootstrap 3.5 which I'm using
<div class="col-xs-4">
Table left side goes here
</div>
<div class="col-xs-8">
Table right side goes here
</div>
And it works fine, as you can see it from here.
however, it's a bit different on Bootstrap 4 Alpha.
<div class="col-2">
<h2 class="sub-header">Test Arear</h2>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td class="col-md-1">Test</td>
</tr>
<tr>
<td class="col-md-1">Test 2</td>
</tr>
<tr>
<td class="col-md-1">Test 3</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-10">
<h2 class="sub-header">Ticket Number</h2>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,002</td>
<td class="col-md-3">1,003</td>
</tr>
<tr>
<td class="col-md-1">1,004</td>
<td class="col-md-2">1,005</td>
<td class="col-md-3">1,006</td>
</tr>
<tr>
<td class="col-md-1">1,002</td>
<td class="col-md-2">1,021</td>
<td class="col-md-3">1,023</td>
</tr>
</tbody>
</table>
</div>
</div>
As you can see results from here.
I want it on the side by side table but it's not side by side. Am I missing something?
You need a row wrapper as bootstrap four is done on flex rather than floats so the columns now need to be wrapped to make them into columns
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap-grid.css" rel="stylesheet"/>
<div class="row">
<div class="col-2">
<h2 class="sub-header">Test Arear</h2>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td class="col-md-1">Test</td>
</tr>
<tr>
<td class="col-md-1">Test 2</td>
</tr>
<tr>
<td class="col-md-1">Test 3</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-10">
<h2 class="sub-header">Ticket Number</h2>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td class="col-md-1">1,001</td>
<td class="col-md-2">1,002</td>
<td class="col-md-3">1,003</td>
</tr>
<tr>
<td class="col-md-1">1,004</td>
<td class="col-md-2">1,005</td>
<td class="col-md-3">1,006</td>
</tr>
<tr>
<td class="col-md-1">1,002</td>
<td class="col-md-2">1,021</td>
<td class="col-md-3">1,023</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Example Bootply
I have tried with this.
<th style="width:500px;overflow:hidden;">
If I have a large description It is going outside the table & I want to fix it.
<div class="Tablecontent">
<div class="table-responsive">
<div style="min-height:300px">
<table class="table table-hover" >
<thead class="tableHeadDesign">
<tr>
<th style="width:40px; overflow:hidden;">S.No.</th>
<th>Name</th>
<th style="max-width:500px;overflow:hidden;">
Description
</th>
<th>Size </th>
<th>Status </th>
<th></th>
</tr>
</thead>
<tbody class="tableBodyDesign">
<tr ng-repeat="x in media |filter:searchText">
<td>$index </td>
<td>{{x.Name}}</td>
<td>{{ x.Description }}</td>
<td > </td>
<td>{{x.Status}}</td>
<td>
<input type="button" class="btn btn-info btn-lg popbtn ViewBtn" value="View Detail"></a></input>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Here I want to fix Description Column.
You can use text ellipsis
see this example
td{
max-width:20px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
table{
width:100%
}
<div class="Tablecontent">
<div class="table-responsive">
<div style="min-height:300px">
<table class="table table-hover" >
<thead class="tableHeadDesign">
<tr>
<th style="width:40px; overflow:hidden;">S.No.</th>
<th>Name</th>
<th style="max-width:500px;overflow:hidden;">
Description
</th>
<th>Size </th>
<th>Status </th>
<th></th>
</tr>
</thead>
<tbody class="tableBodyDesign">
<tr ng-repeat="x in media |filter:searchText">
<td>1 </td>
<td>name</td>
<td>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
<td >dsdsdsdsds </td>
<td>Status</td>
<td>
<input type="button" class="btn btn-info btn-lg popbtn ViewBtn" value="View Detail"></a></input>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Are you looking for text-overflow?
<td style="max-width:500px; display:inline-block; overflow:hidden; text-overflow:clip; white-space:nowrap;">
{{ x.Description }}
</td>
Here is an example:
https://jsfiddle.net/59166290/aan0s31t/15/embedded/result/
Problem solve...
Actually I had fixed the and forgot to set the fixed size of :p