<div className="flex overflow-x-auto shadow-md sm:rounded-lg bg-white dark:bg-gray-800 dark:border-gray-700 w-11/12 justify-center">
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" className="px-6 py-3">
Date
</th>
<th scope="col" className="px-6 py-3">
Job Description
</th>
<th scope="col" className="px-6 py-3">
Location
</th>
<th scope="col" className="px-6 py-3">
Job Type / $ Rate (hourly)
</th>
<th scope="col" className="px-6 py-3">
Details
</th>
</tr>
</thead>
<tbody>
<tr className="bg-white dark:bg-gray-800 dark:border-gray-700">
<th
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-pre-wrap text-xs dark:text-white"
>
WHY NOOOO CENTERRRRRRRRRR
</th>
<td className="px-6 py-4">Sliver</td>
<td className="px-6 py-4">Laptop</td>
<td className="px-6 py-4">$2999</td>
<td className="px-6 py-4">
<a
href="#"
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
>
Edit
</a>
</td>
</tr>
<tr className="bg-white dark:bg-gray-800">
<th
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
Magic Mouse 2
</th>
<td className="px-6 py-4">Black</td>
<td className="px-6 py-4">Accessories</td>
<td className="px-6 py-4">$99</td>
<td className="px-6 py-4">
<a
href="#"
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
>
Edit
</a>
</td>
</tr>
</tbody>
</table>
</div>
I've used flex, flex item-center, and anything that says it will center the table. But, it never moves to the center position no matter what I do.
It is because there is no parent element which is containing the div spanning accross the entire width of screen.
Possible solutions
Try using mx-auto, that will center your table
Code:
<div className="flex mx-auto ...">
<table className="...">
If you want to use flex anyways, try wrapping it with a div and give it width of w-screen
Code:
<div class="flex w-screen justify-center">
<div className="flex ....>
<table> ...
</div>
</div>
Related
I'm trying to make a word wrapper inside a table row, using Tailwind CSS, and it doesn't seem to be working. What am I doing wrong?
I am:
Making the table a: "w-full"
Making the td and the p a "break-all"
Giving a max width to the tr
This is the code:
<div className="py-5 ">
<div className="overflow-x-auto">
<table className="w-full max-w-4xl mx-auto overflow-hidden bg-white divide-y divide-gray-300 rounded-lg whitespace-nowrap">
<thead className="bg-gray-900">
<tr className="text-left text-white">
<th className="px-6 py-4 text-lg font-semibold "> n ° </th>
<th className="px-3 py-4 text-lg font-semibold "> Song </th>
<th className="px-3 py-4 text-lg font-semibold text-center "> Best Singers </th>
<th className="px-6 py-4 text-lg font-semibold text-center"> </th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
<tr className="max-w-xs break-words">
<td className="px-6 py-4">
<div className="flex items-center space-x-3">
<p>
1
</p>
</div>
</td>
<td
style={{ maxWidth: '100px' }}
className="px-3 py-4 break-all"
>
<p
className="break-all"
>
Vivin la vida loca dsadasdasdasd dasdddddddd saddasdasdad
</p>
</td>
<td className="px-3 py-4 text-center">
<p className="text-blue-600 visited:text-purple-600 hover:text-blue-800 hover:underline">
Donkey
</p>
</td>
<td className="px-3 py-4 text-center">
<p className="text-blue-600 visited:text-purple-600 hover:text-blue-800 hover:underline">
Ricky Martin
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
This is how it looks:
You just need to remove the whitespace-nowrap from the table, then it should work.
Uploaded the example here: https://stackblitz.com/edit/react-ewzbi6?file=src/App.js
Might be another part of your styling affecting things here. This works for me:
Don't mean this as an answer, just can't attach pics to comments.
I am trying to group table rows using tailwind and custom CSS like the below screenshot:
I have done something similar like the screenshot but the issue is I want the total and Grade data in the middle, here is my code:
<div className="container mx-auto overflow-x-auto border-x border-t my-10">
<table className="table-auto w-full">
<thead className="border-b">
<tr
style={{ backgroundColor: "#5CB25A" }}
className="text-white font-bold h-10"
>
<th className="text-center md:p-4 p-0 md:w-32 w-10 border-r border-gray-300">
Subject Code
</th>
<th className="text-center md:p-4 p-0 md:w-96 w-none ">
Subject Name
</th>
<th
colSpan={3}
className="text-center p-4 border border-t-0 border-gray-300"
>
Marks
</th>
<th className="text-center md:p-4 p-0 md:w-32 w-10 border-r border-gray-300">
Grade
</th>
</tr>
<tr
style={{ backgroundColor: "#5CB25A" }}
className="border-b border-gray-400 font-bold h-10 text-white"
>
<th className="text-center p-4 border-r text-base"></th>
<th className="text-center p-4"></th>
<th className="text-center p-4 border ">Theory</th>
<th className="text-center p-4 border ">MCQ</th>
<th className="text-center p-4 border ">Total</th>
<th className="text-center p-4"></th>
</tr>
</thead>
<tbody>
<tr className="hover:bg-gray-50 text-center border-b-0 border-b-none h-10">
<td className="p-0 border-l border-r">001</td>
<td className="p-0 border-l border-r">English 1</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r"></td>
<td className="p-0 border-l border-r"></td>
</tr>
<tr className="border -b border-t-0 hover:bg-gray-50 text-center h-10">
<td className="p-0 border-l border-r">001</td>
<td className="p-0 border-l border-r">English 1</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">80</td>
<td className="p-0 border-l border-r">A+</td>
</tr>
<tr className="border-b hover:bg-gray-50 text-center h-10">
<td className="p-4 border">001</td>
<td className="p-4 border">English 1</td>
<td className="p-4 border">40</td>
<td className="p-4 border">40</td>
<td className="p-4 border"></td>
<td className="p-4 border">A+</td>
</tr>
</tbody>
</table>
</div>
Above code UI:
As you can see the total and grade are not in the middle because I have used table rows for the group row.
First I would like you to suggest to remove style={{ backgroundColor: "#5CB25A" }} and add bg-[#5CB25A] in <thead> tag.
<thead class="border-b bg-[#5CB25A]">
Secondly to center, you can use class flex items-center justify-center to center the Grade vertically.
You can also make use of grid class properties to create this table like below
<script src="https://cdn.tailwindcss.com"></script>
<div class="m-2 grid grid-cols-6 bg-gray-50 outline outline-1">
<!-- table head starts -->
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] py-12 text-white">Subject Code</div>
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] py-12 text-white">Subject Name</div>
<div class="col-span-3 flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Marks</div>
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Grade</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Theory</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">MCQ</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Total</div>
<!-- table head ends -->
<!-- table body starts -->
<div class="flex items-center justify-center border-[1px] border-b-0 py-4">
001<br />
001
</div>
<div class="flex items-center justify-center border-[1px] border-b-0">English 1<br />English 1</div>
<div class="flex items-center justify-center border-[1px] border-b-0">40<br />40</div>
<div class="flex items-center justify-center border-[1px] border-b-0">40<br />40</div>
<div class="flex items-center justify-center border-[1px] border-b-0">80</div>
<div class="flex items-center justify-center border-[1px] py-2">A+</div>
<div class="flex items-center justify-center border-[1px] py-2">001</div>
<div class="flex items-center justify-center border-[1px] py-2">English 1</div>
<div class="flex items-center justify-center border-[1px] py-2">40</div>
<div class="flex items-center justify-center border-[1px] py-2">40</div>
<div class="flex items-center justify-center border-[1px] py-2">80</div>
<div class="flex items-center justify-center border-[1px] py-2">A+</div>
<!-- table body ends -->
</div>
Don't forgot to replace class with className as you are working with className
I have the code below for a table based on tailwind css.
If I remove the block class, the table is not scrollable anymore.
Adding the block class to tbody breaks the thead. See Images attached.
CodePen if you want to play with the code. https://codepen.io/hirani89/pen/wvyJKqO?editors=1010
<div class="address">
<h1 class="font-medium leading-tight text-3xl mt-0 mb-2">Recipient</h1>
<div class="item mb-2 md:flex md:flex-wrap md:justify-between">
<div wire:id="rbWM5jbW8w1GcT2ql3DF" class="container w-full px-4 sm:px-8">
<div class="my-2 flex sm:flex-row flex-col">
<div class="block w-1/3 relative">
<span class="h-full absolute inset-y-0 left-0 flex items-center pl-2">
<svg viewBox="0 0 24 24" class="h-4 w-4 fill-current text-gray-500">
<path d="M10 4a6 6 0 100 12 6 6 0 000-12zm-8 6a8 8 0 1114.32 4.906l5.387 5.387a1 1 0 01-1.414 1.414l-5.387-5.387A8 8 0 012 10z">
</path>
</svg>
</span>
<input autocomplete="off" wire:model.debounce.500ms="query" placeholder="Search" class="appearance-none rounded-r rounded-l border border-gray-400 border-b block pl-8 pr-6 py-2 w-full bg-white text-sm placeholder-gray-400 text-gray-700 focus:bg-white focus:placeholder-gray-600 focus:text-gray-700 focus:outline-none">
</div>
</div>
<div class="flex flex-col">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 inline-block w-full sm:px-6 lg:px-8">
<div class="overflow-hidden">
<table class="w-full">
<thead class="bg-white border-b">
<tr>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Select
</th>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Company
</th>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Address
</th>
</tr>
</thead>
<tbody class="h-96 block overflow-y-auto">
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="1">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST </td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="2">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="3">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
MUDGEE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="4">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
ORANGE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="5">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
TAREN POINT
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Without block class in tbody (disables scroll)
With block class in tbody (scroll works but header breaks)
You could add a max-height to your table's parent div and
set position:sticky and top:0 for your thead
<div class="table-wrp block max-h-96">
<table class="w-full">
<thead class="bg-white border-b sticky top-0">
<!-- table head content -->
</thead>
<tbody class="h-96 overflow-y-auto">
<!-- table body content -->
</tbody>
</table>
</div>
Example
<script src="https://cdn.tailwindcss.com"></script>
<div class="min-h-screen bg-gray-100">
<main>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg py-4 px-4">
<form class="mb-4" method="POST" action="https://shipping.local/login">
<div class="address">
<div class="item mb-2 md:flex md:flex-wrap md:justify-between">
<div wire:id="rbWM5jbW8w1GcT2ql3DF" class="container w-full px-4 sm:px-8">
<div class="flex flex-col">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 inline-block w-full sm:px-6 lg:px-8">
<div class="table-wrp block max-h-96">
<table class="w-full">
<thead class="bg-white border-b sticky top-0">
<tr>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Select
</th>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Company
</th>
<th scope="col" class="text-md font-medium text-gray-900 px-6 py-4 text-left">
Address
</th>
</tr>
</thead>
<tbody class="h-96 overflow-y-auto">
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="1">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST </td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="2">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="3">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
MUDGEE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="4">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
ORANGE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="5">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
TAREN POINT
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="1">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST </td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="2">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="3">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
MUDGEE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="4">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
ORANGE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="5">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
TAREN POINT
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="1">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST </td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="2">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
BATHURST
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="3">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
MUDGEE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="4">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
ORANGE
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<input type="checkbox" name="address" value="5">
</td>
<td class="text-sm font-extrabold text-gray-900 font-light px-6 py-4 whitespace-nowrap">
TAREN POINT
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">Address Here Address Here Address Here Address Here Address Here Address Here </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Livewire Component wire-end:rbWM5jbW8w1GcT2ql3DF -->
</div>
</div>
</form>
</div>
</div>
</div>
</main>
</div>
In plain css:
.table-wrp {
max-height: 75vh;
overflow-y: auto;
display:block;
}
thead{
position:sticky;
top:0
}
This is the solution i come up with .
<script src="https://cdn.tailwindcss.com"></script>
<div class="container p-4">
<h1 class="mt-0 mb-2 text-3xl font-medium leading-tight">Recipient</h1>
<div class="item mb-2 md:flex md:flex-wrap md:justify-between">
<div wire:id="rbWM5jbW8w1GcT2ql3DF" class="container w-full px-4 sm:px-8">
<div class="my-2 flex flex-col sm:flex-row">
<div class="relative block w-1/3">
<span class="absolute inset-y-0 left-0 flex h-full items-center pl-2">
<svg viewBox="0 0 24 24" class="h-4 w-4 fill-current text-gray-500">
<path d="M10 4a6 6 0 100 12 6 6 0 000-12zm-8 6a8 8 0 1114.32 4.906l5.387 5.387a1 1 0 01-1.414 1.414l-5.387-5.387A8 8 0 012 10z"></path>
</svg>
</span>
<input autocomplete="off" wire:model.debounce.500ms="query" placeholder="Search" class="block w-full appearance-none rounded-r rounded-l border border-b border-gray-400 bg-white py-2 pl-8 pr-6 text-sm text-gray-700 placeholder-gray-400 focus:bg-white focus:text-gray-700 focus:placeholder-gray-600 focus:outline-none" />
</div>
</div>
<table class=" border-[1px] border-black text-left">
<thead class="">
<tr class="text-left flex justify-items-start">
<th class="text-md px-6 py-4 font-medium text-gray-900 ">Select</th>
<th class="text-md px-6 py-4 font-medium text-gray-900">Company</th>
<th class="text-md px-6 py-4 font-medium text-gray-900">Address</th>
</tr>
</thead>
<!-- Remove the nasty inline CSS fixed height on production and replace it with a CSS class — this is just for demonstration purposes! -->
<tbody class="flex flex-col items-center justify-items-start overflow-y-scroll bg-white text-gray-400" style="height: 50vh;">
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="1" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">BATHURST</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="2" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">BATHURST</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="3" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">MUDGEEEE</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="4" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">ORANGE</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="1" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">BATHURST</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="2" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">BATHURST</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="3" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">MUDGEE</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="4" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">ORANGE</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
<tr class="border-b bg-white transition duration-300 ease-in-out hover:bg-gray-100">
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">
<input type="checkbox" name="address" value="5" />
</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-extrabold text-gray-900">TAREN POINT</td>
<td class="whitespace-nowrap px-6 py-4 text-sm font-light text-gray-900">Address Here Address Here Address Here Address Here Address Here Address Here</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
I am using Bootstrap5 responsive display - hiding elements to display fewer columns on mobile devices. I have been able to do this, however the values of the cells for the columns that are hidden for mobile devices are no longer visible when the columns become visible for larger devices.
I would appreciate any help with this.
I have used the following code within the success block of an AJAX call:
result.data.forEach(datapoint => {
$('#dataTable').append(`<tr>
<td class="fontBurgE" class="shadow p-3 mb-5 bg-white rounded">${datapoint.firstName}</td>
<td class="fontStyleE">${datapoint.lastName}</td>
<td class="d-none d-sm-table-cell" class="fontBurgE" class="shadow p-3 mb-5 bg-white rounded">${datapoint.email}</td>
<td class="d-none d-sm-table-cell" class="fontStyleE" class="shadow p-3 mb-5 bg-white rounded">${datapoint.jobTitle}</td>
<td class="d-none d-md-table-cell" class="fontBurgE">${datapoint.department}</td>
<td class="d-none d-sm-table-cell" class="fontStyleE" class="shadow p-3 mb-5 bg-white rounded">${datapoint.location}</td>
<td class="btn-group>
<button type="button" class="btn btn-white btn-sm rounded-pill py-0 editbutton" data-id="${datapoint.id}" data-bs-toggle="modal" data-bs-target="#editModal" id="edit">
<i class='fas fa-pen editbutton' style='font-size:16px;color:slategrey;position:relative;top:5px; ' data-id="${datapoint.id}" data-bs-toggle="modal" data-bs-target="#editModal" id="edit"></i>
</button>
<button type="button" class="btn btn-white btn-sm rounded-pill py-0 deletebutton" data-id="${datapoint.id}" data-bs-toggle="modal" data-bs-target="#deleteModal">
<i class='far fa-trash-alt' deletebutton' style='font-size:18px;color:thistle' data-id="${datapoint.id}" data-bs-toggle="modal" data-bs-target="#deleteModal"></i>
</button>
</td>
</tr>`)
})
<div class="card mb-3" id="userscroll">
<div class="card-body">
<div class="container">
<table id="datatableID" class="table table-striped table-bordered table-hover display nowrap" cellspacing="0">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th class="d-none d-sm-table-cell">Email</th>
<th class="d-none d-sm-table-cell">Job Title</th>
<th class="d-none d-md-table-cell">Department</th>
<th class="d-none d-sm-table-cell">Location</th>
<th>Action</th>
</tr>
</thead>
<tbody id="dataTable" class="mt-5">
</tbody>
</table>
</div>
</div>
</div>
When I inspect a cell in dev tools I can see the expected value is there and the output is:
<td class="d-none d-sm-table-cell">the expected value</td> ==$0
I'm also using the dataTables plugin. Not sure if this matters.
I am trying to make my site more user friendly, I have a table as shown in the image below which is putting lines under the text of the columns that have bootstrap classes to remove them on smaller screens.
I can't seem to get rid of this issue. I am using standard bootstrap 4 CSS.
My code for the table looks like this, appreciate the help.
<div class='container mx-auto' style='width: 100%'>
<table class='table table-hover' style='width: 100%'>
<thead class='bg-primary text-white'>
<tr>
<th class='bg-primary text-white border-left border-right d-none d-xl-block'>ID</th>
<th class='col-2 bg-primary text-white border-left border-right'>Date</a></th>
<th class='bg-primary text-white d-none d-lg-block'>Venue</th>
<th class='bg-primary text-white'>Comp</th>
<th class='bg-primary text-white border-left border-right d-none d-lg-block'>M/F</th>
<th class='col-2 bg-primary text-white border-left border-right'>Home Team</th>
<th colspan='2' class='col-1 bg-primary text-white border-left border-right text-center'>Score</th>
<th class='col-2 bg-primary text-white border-left border-right'>Away Team</th>
<th class='bg-primary text-white border-left border-right d-none d-md-block'>Referee</th>
<th class='bg-primary text-white border-left border-right text-center'>Edit</th>
<th class='bg-primary text-white border-left border-right text-center'>Delete</th>
</tr>
</thead>
<tbody>
<?php
if($result = mysqli_query($link,$sql)) {
while ($row = mysqli_fetch_array($result)) {
echo "
<tr>
<td class='border-left border-right d-none d-xl-block'>{$row[6]}</td> <!-- ID -->
<td class='border-left border-right'><a href='viewMatch.php?matchID={$row[6]}'>{$row[0]}</a></td><!-- Date -->
<td class='text-left border-left border-right d-none d-lg-block'>{$row[1]}</td><!-- Venue -->
<td class='border-left border-right'>{$row[2]}</td><!-- Comp -->
<td class='border-left border-right d-none d-lg-block' style='text-align:center'>{$row[7]}</td><!-- Gender -->
<td class='border-left border-right'>{$row[3]}</td><!-- Home Team -->
<td class='border-left border-right' style='text-align:center'>{$row[8]}</td><!-- Home Score -->
<td class='border-left border-right' style='text-align:center'>{$row[9]}</td><!-- Away Score -->
<td class='border-left border-right'>{$row[4]}</td><!-- Away Team -->
<td class='border-left border-right d-none d-md-block'>{$row[5]}</td><!-- Referee -->";
if($role >= 5) {
echo "
<td class='border-left border-right text-center'>
<form action='../edit/updateMatch.php' method='POST' onsubmit=''/>
<input type='hidden' name='q' value='".$row[6]."'/><button class='btn btn-primary' type='Submit' value='Update'><i class='fa fa-edit'></i></button>
</form>
</td>";
}
if($role > 5) {
echo "
<td style='text-align:center'>
<form action='../delete/deleteMatch.php' method='POST' onsubmit='' onclick='return confirm(`do you want to delete {$row[3]} vs {$row[4]} on the {$row[0]}`)'/><input type='hidden' name='q' value='".$row[6]."' /><button class='btn btn-danger' type='Submit' value='Delete'><i class='fa fa-trash'></i></button>
</form>
</td>";
}
echo "
</tr>";
}
echo "
</tbody>
</table>
</div>
</div>";
the problem is with -block suffix in the classes. You should use -table-cell instead.
See more in documentation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class='container mx-auto' style='width: 100%'>
<table class='table table-hover' style='width: 100%'>
<thead class='bg-primary text-white'>
<tr>
<th class='bg-primary text-white border-left border-right d-none d-xl-table-cell'>ID</th>
<th class='col-2 bg-primary text-white border-left border-right'>Date</a></th>
<th class='bg-primary text-white d-none d-lg-table-cell'>Venue</th>
<th class='bg-primary text-white'>Comp</th>
<th class='bg-primary text-white border-left border-right d-none d-lg-table-cell'>M/F</th>
<th class='col-2 bg-primary text-white border-left border-right'>Home Team</th>
<th colspan='2' class='col-1 bg-primary text-white border-left border-right text-center'>Score</th>
<th class='col-2 bg-primary text-white border-left border-right'>Away Team</th>
<th class='bg-primary text-white border-left border-right d-none d-md-table-cell'>Referee</th>
<th class='bg-primary text-white border-left border-right text-center'>Edit</th>
<th class='bg-primary text-white border-left border-right text-center'>Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>