Published on

Ultimate Guide: Create A Modal Blog Post With Tailwind CSS

Modal blog post

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 Modal blog post ui component

This is a modal blog post example

Why use Tailwind CSS to build a Modal blog post ui component?

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

The preview of Modal blog post ui component

Free download of the Modal blog post's source code

The source code of Modal blog post ui component

<!-- This is an example component -->
<div class="bg-white overflow-hidden shadow-none">
    <div class="grid grid-cols-3 min-w-full">

        <div class="col-span-2 w-full">
            <img class="w-full max-w-full min-w-full"
                src="https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                alt="Description">
        </div>

        <div class="col-span-1 relative pl-4">
            <header class="border-b border-grey-400">
                <a href="#" class="block cursor-pointer py-4 flex items-center text-sm outline-none focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                    <img src="https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" class="h-9 w-9 rounded-full object-cover"
                    alt="user" />
                    <p class="block ml-2 font-bold">Paul</p>
                </a>
            </header>

            <div >
                <div class="pt-1">
                    <div class="text-sm mb-2 flex flex-start items-center">
                        <div>
                            <a href="#" class="cursor-pointer flex items-center text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                                <img class="h-8 w-8 rounded-full object-cover"
                                src="https://images.pexels.com/photos/1450082/pexels-photo-1450082.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260"
                                alt="user" />
                            </a>
                        </div>
                        <p class="font-bold ml-2">
                            <a class="cursor-pointer">Joshua:</a>
                            <span class="text-gray-700 font-medium ml-1">
                                Good post
                            </span>
                        </p>
                    </div>
                </div>
                <div class="text-sm mb-2 flex flex-start items-center">
                    <div>
                        <a href="#" class="cursor-pointer flex items-center text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                            <img class="h-8 w-8 rounded-full object-cover"
                            src="https://images.pexels.com/photos/3861456/pexels-photo-3861456.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                            alt="user" />
                        </a>
                    </div>
                    <p class="font-bold ml-2">
                        <a class="cursor-pointer">Kesha:</a>
                        <span class="text-gray-700 font-medium ml-1">
                            This is amazing
                        </span>
                    </p>
                </div>
            </div>

            <div class="absolute bottom-0 left-0 right-0 pl-4">
                <div class="pt-4">
                    <div class="mb-2">
                        <div class="flex items-center">
                            <span class="mr-3 inline-flex items-center cursor-pointer">
                                <svg class="fill-heart text-gray-700 inline-block h-7 w-7 heart" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
                                </svg>
                            </span>
                            <span class="mr-3 inline-flex items-center cursor-pointer">
                                <svg class="text-gray-700 inline-block h-7 w-7 " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
                                </svg>
                            </span>
                        </div>
                        <span class="text-gray-600 text-sm font-bold">2344 Likes</span>
                    </div>
                    <span class="block ml-2 text-xs text-gray-600">5 minutes</span>
                </div>

                <div class="pt-4 pb-1 pr-3">
                    <div class="flex items-start">
                        <textarea class="w-full resize-none outline-none appearance-none" aria-label="Agrega un comentario..." placeholder="Agrega un comentario..."  autocomplete="off" autocorrect="off" style="height: 36px;"></textarea>
                        <button class="mb-2 focus:outline-none border-none bg-transparent text-blue-600">Publicar</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

How to build a Modal blog post with Tailwind CSS?

Install tailwind css of verion 2.0.3

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

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

All the unility class needed to build a Modal blog post component

  • bg-white
  • overflow-hidden
  • grid
  • grid-cols-3
  • min-w-full
  • w-full
  • max-w-full
  • relative
  • pl-4
  • border-b
  • border-grey-400
  • block
  • py-4
  • flex
  • text-sm
  • focus:border-gray-300
  • h-9
  • w-9
  • ml-2
  • pt-1
  • mb-2
  • flex-start
  • border-2
  • border-transparent
  • h-8
  • w-8
  • text-gray-700
  • ml-1
  • absolute
  • bottom-0
  • left-0
  • right-0
  • pt-4
  • mr-3
  • inline-flex
  • inline-block
  • h-7
  • w-7
  • text-gray-600
  • text-xs
  • pb-1
  • pr-3
  • border-none
  • bg-transparent
  • text-blue-600

45 steps to build a Modal blog post component with Tailwind CSS

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

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

  3. Use grid to create a grid container.

  4. Use grid to create a grid container.

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

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

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

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

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

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

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

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

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

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

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

  16. Control the border color of an element to gray-300 using the focus:border-gray-300 utilities on focus.

  17. Use h-9 to set an element to a fixed height(2.25rem).

  18. Use w-9 to set an element to a fixed width(2.25rem).

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

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

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

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

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

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

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

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

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

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

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

  30. Use the bottom-0 utilities to set the bottom position of a positioned element to 0rem.

  31. Use the left-0 utilities to set the left position of a positioned element to 0rem.

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

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

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

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

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

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

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

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

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

  41. Control the padding on bottom side of an element to 0.25rem using the pb-1 utilities.

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

  43. Control the border color of an element to none using the border-none utilities.

  44. Control the background color of an element to transparent using the bg-transparent utilities.

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

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to build a Modal blog post components, learn and follow along to implement your own components.