Published on

The Ultimate Guide To Help You Build A Table with actions inside With Tailwind CSS

Tags
Table with actions inside

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 Table with actions inside ui component

Table with actions inside the tr td

Why use Tailwind CSS to build a Table with actions inside ui component?

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

The preview of Table with actions inside ui component

Free download of the Table with actions inside's source code

The source code of Table with actions inside ui component

<div class="max-w-7xl mx-auto">
    <div class="inline-block min-w-full py-2 align-middle">
        <div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
            <table class="min-w-full divide-y divide-gray-300">
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">#</th>
                        <th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900">User</th>
                        <th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Email</th>
                        <th scope="col" class="px-3 py-3.5 text-center text-sm font-semibold text-gray-900">Status</th>
                        <th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
                            <span class="sr-only">Actions</span>
                        </th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 bg-white">
                    <tr>
                        <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-semibold text-gray-900 sm:pl-6">1</td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">Norma Nova</td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm">
                            [email protected]
                        </td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm">
                            <span class="flex justify-center">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-green-500" viewBox="0 0 20 20" fill="currentColor">
                                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
                                </svg>
                            </span>
                        </td>
                        <td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
                            <div class="inline-block text-left" x-data="{ menu: false }">
                                <button x-on:click="menu = ! menu" type="button" class="flex items-center text-gray-400 hover:text-gray-600 focus:outline-none" id="menu-button" aria-expanded="true" aria-haspopup="true">
                                    <span class="sr-only"></span>
                                    <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                                    <path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
                                    </svg>
                                </button>
                                <div x-show="menu" x-on:click.away="menu = false" class="origin-top-right absolute right-32 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 divide-y divide-gray-100 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
                                    <div class="" role="none">
                                        <a href="#" class="text-gray-500 font-medium hover:text-gray-900 hover:bg-gray-50 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">
                                            Detalle
                                        </a>
                                    </div>
                                    <div class="" role="none">
                                        <a href="#" class="text-gray-500 font-medium hover:text-gray-900 hover:bg-gray-50 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">
                                            Editar
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-semibold text-gray-900 sm:pl-6">2</td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">Oscar Tellez</td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm">
                            [email protected]
                        </td>
                        <td class="whitespace-nowrap px-3 py-4 text-sm">
                            <span class="flex justify-center">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-red-500" viewBox="0 0 20 20" fill="currentColor">
                                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
                                </svg>
                            </span>
                        </td>
                        <td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
                            <div class="inline-block text-left" x-data="{ menu: false }">
                                <button x-on:click="menu = ! menu" type="button" class="flex items-center text-gray-400 hover:text-gray-600 focus:outline-none" id="menu-button" aria-expanded="true" aria-haspopup="true">
                                    <span class="sr-only"></span>
                                    <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                                    <path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
                                    </svg>
                                </button>
                                <div x-show="menu" x-on:click.away="menu = false" class="origin-top-right absolute right-32 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 divide-y divide-gray-100 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
                                    <div class="" role="none">
                                        <a href="#" class="text-gray-500 font-medium hover:text-gray-900 hover:bg-gray-50 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">
                                            Detalle
                                        </a>
                                    </div>
                                    <div class="" role="none">
                                        <a href="#" class="text-gray-500 font-medium hover:text-gray-900 hover:bg-gray-50 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">
                                            Editar
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>

How to build a Table with actions inside with Tailwind CSS?

Install tailwind css of verion 2.2.19

Use the script html tag to import the script of Tailwind CSS of the version 2.2.19

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to build a Table with actions inside component

  • max-w-7xl
  • mx-auto
  • inline-block
  • min-w-full
  • py-2
  • overflow-hidden
  • bg-gray-50
  • py-3.5
  • pl-4
  • pr-3
  • text-left
  • text-sm
  • text-gray-900
  • sm:pl-6
  • px-3
  • text-center
  • relative
  • pl-3
  • pr-4
  • sm:pr-6
  • bg-white
  • py-4
  • text-gray-500
  • flex
  • h-5
  • w-5
  • text-green-500
  • text-right
  • text-gray-400
  • hover:text-gray-600
  • absolute
  • right-32
  • mt-2
  • w-56
  • hover:text-gray-900
  • hover:bg-gray-50
  • block
  • px-4
  • text-red-500

39 steps to build a Table with actions inside component with Tailwind CSS

  1. Set the maximum width/height of an element using the max-w-7xl utilities.

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

  3. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

  4. Set the minimum width/height of an element using the min-w-full utilities.

  5. Control the vertical padding of an element to 0.5rem using the py-2 utilities.

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

  7. Control the background color of an element to gray-50 using the bg-gray-50 utilities.

  8. Control the vertical padding of an element to 3.5 using the py-3.5 utilities.

  9. Set the left padding of an element to 1rem using the pl-4 utilities class

  10. Control the padding on right side of an element to 0.75rem using the pr-3 utilities.

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

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

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

  14. Set the left padding of an element to 1.5rem at only small screen sizes using the sm:pl-6 utilities class

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

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

  17. Use relative to position an element according to the normal flow of the document.

  18. Set the left padding of an element to 0.75rem using the pl-3 utilities class

  19. Control the padding on right side of an element to 1rem using the pr-4 utilities.

  20. Control the padding on right side of an element to 1.5rem at only small screen sizes using the sm:pr-6 utilities.

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

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

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

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

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

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

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

  28. Control the text color of an element to right using the text-right utilities.

  29. Control the text color of an element to gray-400 using the text-gray-400 utilities.

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

  31. 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.

  32. Use the right-32 utilities to set the right position of a positioned element to 8rem.

  33. Control the margin on top side of an element to 0.5rem using the mt-2 utilities.

  34. Use w-56 to set an element to a fixed width(14rem).

  35. Control the text color of an element to gray-900 on hover using the hover:text-gray-900 utilities.

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

  37. Use inline utilities to put the element on its own line and fill its parent.

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

  39. Control the text color of an element to red-500 using the text-red-500 utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to build a Table with actions inside components, learn and follow along to implement your own components.