Published on

The Ultimate Guide To Help You Build A Responsive Tailwind table With Tailwind CSS

Tags
Responsive Tailwind table

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

The description of Responsive Tailwind table ui component

Got the design inspiration from steve schoger tailwind ui table designs and thought of making it responsive to fit all viewports

Why use Tailwind CSS to make a Responsive Tailwind table ui component?

  • It can make the building process of Responsive Tailwind table ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Responsive Tailwind table component file.

The preview of Responsive Tailwind table ui component

Free download of the Responsive Tailwind table's source code

The source code of Responsive Tailwind table ui component

<div class="container mx-auto pt-4 px-4 py-16 ">
	<div class="container">
	<h1 class="mb-8">
    Responsive Tailwind Table
  </h1>
	<div id="app" style="overflow-x:auto;">
		<table class="w-full shadow-lg rounded">
			<thead>
				<tr class="text-left bg-gray-300 border-b border-grey uppercase">
			        <th class="px-2 py-6"></th>
			        <th class="text-sm text-gray-700">Name</th>
			        <th class="hidden md:table-cell  text-sm text-gray-700">Mobile</th>
			        <th class="hidden md:table-cell text-sm text-gray-700">Email</th>
			        <th></th>
		      	</tr>
			</thead>
	        <tbody class="bg-white">
		      	<tr class="accordion border-b border-grey-light hover:bg-gray-100" @click="panel = true">
			        <td class="px-3 py-4">
			         	<span class="bg-white border-2 ml-1 rounded border-gray-400 w-5 h-5 flex flex-shrink-0 focus-within:border-blue-500">
							<input type="checkbox" class="opacity-0 absolute">
							<svg class="fill-current hidden w-4 h-4 text-green-500 pointer-events-none" viewBox="0 0 20 20"><path d="M0 11l2-2 5 5L18 3l2 2L7 18z"/></svg>
						</span>
			        </td>
			        <td class="flex inline-flex items-center">
			        	<span>
			        		 <img
					        class="hidden mr-1 md:mr-2 md:inline-block h-8 w-8 rounded-full object-cover"
					        src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=4&w=144&h=144&q=80"
					        alt=""
					        />
			        	</span>
			        	<span class="py-3 w-40">
			        		 <p class="text-gray-800 text-sm">Bernard Owiredu {{panel}}</p>
			        		 <p class="md:hidden text-xs text-gray-600 font-medium">244224317</p>
			          		 <p class="hidden md:table-cell text-xs text-gray-500 font-medium">Manager</p>
			        	</span>
			        </td>
			        <td class="hidden md:table-cell">
			          <p class="text-sm text-gray-800 font-medium">244224317</p>
			          <p class="text-xs text-gray-500 font-medium">[email protected]</p>
			        </td>
			        <td class="hidden md:table-cell">
			          <p class="text-sm text-gray-700 font-medium">[email protected]</p>
			        </td>
			        <td>
			          <svg
			            class="mr-3 md:mr-1 h-12 w-6 fill-current text-grey-dark"
			            xmlns="http://www.w3.org/2000/svg"
			            viewBox="0 0 20 20"
			          >
			            <path
			              d="M4 12a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm6 0a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm6 0a2 2 0 1 1 0-4 2 2 0 0 1 0 4z"
			            />
			          </svg>
			        </td>
		      	</tr>
		     
		      	<tr @click="panel = false" :class="panel ? 'table-row bg-gray-100' : 'hidden'"  class="border-b border-grey-light w-full">
		      		<td class=" py-4 px-3 text-sm text-gray-800 font-medium">1</td>
		      		<td class="text-sm text-gray-800 font-medium">2</td>
		      		<td class="text-sm text-gray-800 font-medium">3</td>
		      	</tr>
		
		      	<tr class="accordion border-b border-grey-light items-center">
			        <td class="px-3 py-4">
			         	<span class="bg-white border-2 ml-1 rounded border-gray-400 w-5 h-5 flex flex-shrink-0 focus:border-blue-500">
							<input type="checkbox" class="opacity-0 absolute">
							<svg class="fill-current hidden w-4 h-4 text-green-500 pointer-events-none" viewBox="0 0 20 20"><path d="M0 11l2-2 5 5L18 3l2 2L7 18z"/></svg>
						</span>
			        </td>
			        <td class="flex inline-flex items-center">
			        	<span>
			        		 <img
					        class="hidden mr-1 md:mr-2 md:inline-block h-8 w-8 rounded-full object-cover"
					        src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=4&w=144&h=144&q=80"
					        alt=""
					        />
			        	</span>
			        	<span class="py-3">
			        		 <p class="text-gray-800 text-sm">Molly Sanders</p>
			          		 <p class="md:hidden text-xs text-gray-600 font-medium">244224317</p>
			          		 <p class="hidden md:table-cell text-xs text-gray-500 font-medium">Manager</p>
			        	</span>
			        </td>
			        <td class="hidden md:table-cell">
			          <p class="text-sm text-gray-800 font-medium">244224317</p>
			          <p class="text-xs text-gray-500 font-medium">[email protected]</p>
			        </td>
			        <td class="hidden md:table-cell">
			          <p class="text-sm text-gray-700 font-medium">[email protected]</p>
			        </td>
			        <td>
			          <svg
			            class="h-12 w-6 fill-current text-grey-dark"
			            xmlns="http://www.w3.org/2000/svg"
			            viewBox="0 0 20 20"
			          >
			            <path
			              d="M4 12a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm6 0a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm6 0a2 2 0 1 1 0-4 2 2 0 0 1 0 4z"
			            />
			          </svg>
			        </td>
		      	</tr>
		      	<tr :class="panel ? 'panel-show' : 'hidden'" class="border-b border-grey-light">
		      		<td class=" py-4 px-3 text-sm text-gray-800 font-medium">1</td>
		      		<td class="text-sm text-gray-800 font-medium">2</td>
		      		<td class="text-sm text-gray-800 font-medium">3</td>
		      	</tr>
	     </tbody>
	    </table>
	</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
	new Vue({
		    el: '#app',
		    data: {
		      panel: false,
		    },
	  	})
</script>

How to make a Responsive Tailwind table with Tailwind CSS?

Install tailwind css of verion 1.0.4

Use the link html tag to import the stylesheet of Tailwind CSS of the version 1.0.4

<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">

All the unility class needed to make a Responsive Tailwind table component

  • mx-auto
  • pt-4
  • px-4
  • py-16
  • mb-8
  • w-full
  • text-left
  • bg-gray-300
  • border-b
  • border-grey
  • px-2
  • py-6
  • text-sm
  • text-gray-700
  • hidden
  • md:table-cell
  • bg-white
  • border-grey-light
  • hover:bg-gray-100
  • px-3
  • py-4
  • border-2
  • ml-1
  • border-gray-400
  • w-5
  • h-5
  • flex
  • flex-shrink-0
  • focus-within:border-blue-500
  • absolute
  • w-4
  • h-4
  • text-green-500
  • inline-flex
  • mr-1
  • md:mr-2
  • md:inline-block
  • h-8
  • w-8
  • py-3
  • w-40
  • text-gray-800
  • md:hidden
  • text-xs
  • text-gray-600
  • text-gray-500
  • mr-3
  • md:mr-1
  • h-12
  • w-6
  • text-grey-dark
  • table-row
  • bg-gray-100
  • focus:border-blue-500

54 steps to make a Responsive Tailwind table component with Tailwind CSS

  1. Control the horizontal margin of an element to auto using the mx-auto utilities.

  2. Control the padding on top side of an element to 1rem using the pt-4 utilities.

  3. Control the horizontal padding of an element to 1rem using the px-4 utilities.

  4. Control the vertical padding of an element to 4rem using the py-16 utilities.

  5. Control the margin on bottom side of an element to 2rem using the mb-8 utilities.

  6. Use w-full to set an element to a 100% based width.

  7. Control the text color of an element to left using the text-left utilities.

  8. Control the background color of an element to gray-300 using the bg-gray-300 utilities.

  9. Control the border color of an element to b using the border-b utilities.

  10. Control the border color of an element to grey using the border-grey utilities.

  11. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

  12. Control the vertical padding of an element to 1.5rem using the py-6 utilities.

  13. Control the text color of an element to sm using the text-sm utilities.

  14. Control the text color of an element to gray-700 using the text-gray-700 utilities.

  15. Use hidden to set an element to display: none and remove it from the page layout.

  16. Use the table utilities to create elements that behave like their respective table elements at only medium screen sizes.

  17. Control the background color of an element to white using the bg-white utilities.

  18. Control the border color of an element to grey-light using the border-grey-light utilities.

  19. Control the background color of an element to gray-100 using the hover:bg-gray-100 utilities on hover.

  20. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  21. Control the vertical padding of an element to 1rem using the py-4 utilities.

  22. Control the border color of an element to 0.5rem using the border-2 utilities.

  23. Control the margin on left side of an element to 0.25rem using the ml-1 utilities.

  24. Control the border color of an element to gray-400 using the border-gray-400 utilities.

  25. Use w-5 to set an element to a fixed width(1.25rem).

  26. Use h-5 to set an element to a fixed height(1.25rem).

  27. Use flex to create a block-level flex container.

  28. Use flex to create a block-level flex container.

  29. Control the border color of an element to blue-500 using the focus-within:border-blue-500 utilitiesundefined.

  30. Use absolute to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.

  31. Use w-4 to set an element to a fixed width(1rem).

  32. Use h-4 to set an element to a fixed height(1rem).

  33. Control the text color of an element to green-500 using the text-green-500 utilities.

  34. Use inline-flex to create an inline flex container that flows with text.

  35. Control the margin on right side of an element to 0.25rem using the mr-1 utilities.

  36. Control the margin on right side of an element to 0.5rem at only medium screen sizes using the md:mr-2 utilities.

  37. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent at only medium screen sizes.

  38. Use h-8 to set an element to a fixed height(2rem).

  39. Use w-8 to set an element to a fixed width(2rem).

  40. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

  41. Use w-40 to set an element to a fixed width(10rem).

  42. Control the text color of an element to gray-800 using the text-gray-800 utilities.

  43. Use hidden to set an element to display: none and remove it from the page layout at only medium screen sizes.

  44. Control the text color of an element to xs using the text-xs utilities.

  45. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  46. Control the text color of an element to gray-500 using the text-gray-500 utilities.

  47. Control the margin on right side of an element to 0.75rem using the mr-3 utilities.

  48. Control the margin on right side of an element to 0.25rem at only medium screen sizes using the md:mr-1 utilities.

  49. Use h-12 to set an element to a fixed height(3rem).

  50. Use w-6 to set an element to a fixed width(1.5rem).

  51. Control the text color of an element to grey-dark using the text-grey-dark utilities.

  52. Use the table utilities to create elements that behave like their respective table elements.

  53. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  54. Control the border color of an element to blue-500 using the focus:border-blue-500 utilities on focus.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to make a Responsive Tailwind table components, learn and follow along to implement your own components.