Published on

Best Ways To Make A Mobile Responsive Table With Tailwind CSS

Tags
mobile responsive 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 mobile responsive table ui component

Simple responsive table for mobile.

Why use Tailwind CSS to make a mobile responsive table ui component?

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

The preview of mobile responsive table ui component

Free download of the mobile responsive table's source code

The source code of mobile responsive table ui component

<body class="flex items-center justify-center">
	<div class="container">
		<table class="w-full flex flex-row flex-no-wrap sm:bg-white rounded-lg overflow-hidden sm:shadow-lg my-5">
			<thead class="text-white">
				<tr class="bg-teal-400 flex flex-col flex-no wrap sm:table-row rounded-l-lg sm:rounded-none mb-2 sm:mb-0">
					<th class="p-3 text-left">Name</th>
					<th class="p-3 text-left">Email</th>
					<th class="p-3 text-left" width="110px">Actions</th>
				</tr>
				<tr class="bg-teal-400 flex flex-col flex-no wrap sm:table-row rounded-l-lg sm:rounded-none mb-2 sm:mb-0">
					<th class="p-3 text-left">Name</th>
					<th class="p-3 text-left">Email</th>
					<th class="p-3 text-left" width="110px">Actions</th>
				</tr>
                <tr class="bg-teal-400 flex flex-col flex-no wrap sm:table-row rounded-l-lg sm:rounded-none mb-2 sm:mb-0">
                  <th class="p-3 text-left">Name</th>
                  <th class="p-3 text-left">Email</th>
                  <th class="p-3 text-left" width="110px">Actions</th>
              </tr>
                <tr class="bg-teal-400 flex flex-col flex-no wrap sm:table-row rounded-l-lg sm:rounded-none mb-2 sm:mb-0">
                  <th class="p-3 text-left">Name</th>
                  <th class="p-3 text-left">Email</th>
                  <th class="p-3 text-left" width="110px">Actions</th>
              </tr>
			</thead>
			<tbody class="flex-1 sm:flex-none">
				<tr class="flex flex-col flex-no wrap sm:table-row mb-2 sm:mb-0">
					<td class="border-grey-light border hover:bg-gray-100 p-3">John Covv</td>
					<td class="border-grey-light border hover:bg-gray-100 p-3 truncate">[email protected]</td>
					<td class="border-grey-light border hover:bg-gray-100 p-3 text-red-400 hover:text-red-600 hover:font-medium cursor-pointer">Delete</td>
				</tr>
				<tr class="flex flex-col flex-no wrap sm:table-row mb-2 sm:mb-0">
					<td class="border-grey-light border hover:bg-gray-100 p-3">Michael Jackson</td>
					<td class="border-grey-light border hover:bg-gray-100 p-3 truncate">[email protected]</td>
					<td class="border-grey-light border hover:bg-gray-100 p-3 text-red-400 hover:text-red-600 hover:font-medium cursor-pointer">Delete</td>
				</tr>
                <tr class="flex flex-col flex-no wrap sm:table-row mb-2 sm:mb-0">
                    <td class="border-grey-light border hover:bg-gray-100 p-3">Julia</td>
                    <td class="border-grey-light border hover:bg-gray-100 p-3 truncate">[email protected]</td>
                    <td class="border-grey-light border hover:bg-gray-100 p-3 text-red-400 hover:text-red-600 hover:font-medium cursor-pointer">Delete</td>
                </tr>
                <tr class="flex flex-col flex-no wrap sm:table-row mb-2 sm:mb-0">
                  <td class="border-grey-light border hover:bg-gray-100 p-3">Martin Madrazo</td>
                  <td class="border-grey-light border hover:bg-gray-100 p-3 truncate">[email protected]</td>
                  <td class="border-grey-light border hover:bg-gray-100 p-3 text-red-400 hover:text-red-600 hover:font-medium cursor-pointer">Delete</td>
                </tr>
			</tbody>
		</table>
	</div>
</body>

<style>
  html,
  body {
    height: 100%;
  }

  @media (min-width: 640px) {
    table {
      display: inline-table !important;
    }

    thead tr:not(:first-child) {
      display: none;
    }
  }

  td:not(:last-child) {
    border-bottom: 0;
  }

  th:not(:last-child) {
    border-bottom: 2px solid rgba(0, 0, 0, .1);
  }
</style>

How to make a mobile responsive table with Tailwind CSS?

Install tailwind css of verion 1.2.0

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

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

All the unility class needed to make a mobile responsive table component

  • flex
  • w-full
  • flex-row
  • flex-no-wrap
  • sm:bg-white
  • overflow-hidden
  • my-5
  • text-white
  • bg-teal-400
  • flex-col
  • flex-no
  • sm:table-row
  • mb-2
  • sm:mb-0
  • p-3
  • text-left
  • flex-1
  • sm:flex-none
  • border-grey-light
  • hover:bg-gray-100
  • text-red-400
  • hover:text-red-600

22 steps to make a mobile responsive table component with Tailwind CSS

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

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

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

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

  5. Control the background color of an element to white using the sm:bg-white utilities at only small screen sizes.

  6. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  7. Control the vertical margin of an element to 1.25rem using the my-5 utilities.

  8. Control the text color of an element to white using the text-white utilities.

  9. Control the background color of an element to teal-400 using the bg-teal-400 utilities.

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

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

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

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

  14. Control the margin on bottom side of an element to 0rem at only small screen sizes using the sm:mb-0 utilities.

  15. Control the padding on all sides of an element to 0.75rem using the p-3 utilities.

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

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

  18. Use flex to create a block-level flex container at only small screen sizes.

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

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

  21. Control the text color of an element to red-400 using the text-red-400 utilities.

  22. Control the text color of an element to red-600 on hover using the hover:text-red-600 utilities.

Conclusion

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