Published on

6 Tips To Make A Photo Gallery Card With Tailwind CSS

Photo gallery card

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.

A simple photo card with floating stock button with view, edit and remove options.

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

Free download of the Photo gallery card's source code

<!-- This is an example component -->
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
<div class="w-full p-6 mx-auto">
    <div class="shadow-md rounded bg-white overflow-hidden relative">
        <div class="absolute top-2 right-2">
            <div class="relative" x-data="{ isOpen: false }">
                <button
                    @click="isOpen = !isOpen"
                    class="p-2 bg-gray-100 rounded-full hover:bg-gray-200 focus:outline-none focus:ring"
                >
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-7 w-7 cursor-pointer" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z" />
                    </svg>
                </button>

                <!-- Dropdown card -->
                <div
                    @click.away="isOpen = false"
                    x-show.transition.opacity="isOpen"
                    class="absolute w-48 max-w-md mt-3 transform bg-white rounded-md shadow-lg -translate-x-3/4 min-w-max overflow-hidden"
                >
                    <div class="p-2 font-medium border-b">
                        <span class="text-gray-800">Actions</span>
                    </div>
                    <ul class="flex flex-col">

                        <li>
                            <a href="#" class="flex items-center px-2 py-1 transition hover:bg-gray-100">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-eye-fill " viewBox="0 0 16 16">
                                    <path d="M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z"></path>
                                    <path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"></path>
                                </svg>
                                <span class="ml-2">View</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="flex items-center px-2 py-1 transition hover:bg-gray-100 ">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square " viewBox="0 0 16 16">
                                    <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456l-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"></path>
                                    <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"></path>
                                </svg>
                                <span class="ml-2">Edit</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="flex items-center px-2 py-1 transition hover:bg-gray-100">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill " viewBox="0 0 16 16">
                                    <path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"></path>
                                </svg>
                                <span class="ml-2">Remove</span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="grid grid-cols-2 h-64">
            <div class="h-64 overflow-hidden">
                <img class="object-cover h-64 w-full" src="https://images.freeimages.com/images/small-previews/20c/my-puppy-maggie-1362787.jpg">
            </div>
            <div class="h-64 overflow-hidden">
                <img class="object-cover h-32 w-full" src="https://images.freeimages.com/images/small-previews/e71/frog-1371919.jpg">
                <img class="object-cover h-32 w-full" src="https://cdn.pixabay.com/photo/2015/07/27/19/47/turtle-863336__340.jpg">
            </div>
        </div>
        <div class="p-3">
            <div class="block md:flex justify-between">
                <div>
                    <h3 class="font-medium">Card Title</h3>
                    <span class="text-sm text-gray-500">Author Name &bull; [email protected]</span>
                </div>

                <div class="">
                    <div>
                        <span class="text-sm text-gray-500">01-20-2020 12:30</span>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

Install tailwind css of verion 2.2.4

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

<script src="https://cdn.tailwindcss.com"></script>
  • w-full
  • p-6
  • mx-auto
  • bg-white
  • overflow-hidden
  • relative
  • absolute
  • top-2
  • right-2
  • p-2
  • bg-gray-100
  • hover:bg-gray-200
  • h-7
  • w-7
  • w-48
  • max-w-md
  • mt-3
  • min-w-max
  • border-b
  • text-gray-800
  • flex
  • flex-col
  • px-2
  • py-1
  • hover:bg-gray-100
  • ml-2
  • grid
  • grid-cols-2
  • h-64
  • h-32
  • p-3
  • block
  • md:flex
  • text-sm
  • text-gray-500
  1. Use w-full to set an element to a 100% based width.

  2. Control the padding on all sides of an element to 1.5rem using the p-6 utilities.

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

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

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

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

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

  8. Use the top-2 utilities to set the top position of a positioned element to 0.5rem.

  9. Use the right-2 utilities to set the right position of a positioned element to 0.5rem.

  10. Control the padding on all sides of an element to 0.5rem using the p-2 utilities.

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

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

  13. Use h-7 to set an element to a fixed height(1.75rem).

  14. Use w-7 to set an element to a fixed width(1.75rem).

  15. Use w-48 to set an element to a fixed width(12rem).

  16. Set the maximum width/height of an element using the max-w-md utilities.

  17. Control the margin on top side of an element to 0.75rem using the mt-3 utilities.

  18. Set the minimum width/height of an element using the min-w-max utilities.

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

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

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

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

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

  24. Control the vertical padding of an element to 0.25rem using the py-1 utilities.

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

  26. Control the margin on left side of an element to 0.5rem using the ml-2 utilities.

  27. Use grid to create a grid container.

  28. Use grid to create a grid container.

  29. Use h-64 to set an element to a fixed height(16rem).

  30. Use h-32 to set an element to a fixed height(8rem).

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

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

  33. Use flex to create a block-level flex container at only medium screen sizes.

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

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

Conclusion

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