Published on

How To Make A Example Chat With Tailwind CSS From Scratch

Tags
Example Chat

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 Example Chat ui component

This is example chat

Why use Tailwind CSS to make a Example Chat ui component?

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

The preview of Example Chat ui component

Free download of the Example Chat's source code

The source code of Example Chat ui component

<!-- This is an example component -->
<div class="w-screen">
    <div class="grid grid-cols-3 min-w-full border rounded" style="min-height: 80vh;">
            <div class="col-span-1 bg-white border-r border-gray-300">
                <div class="my-3 mx-3 ">
                    <div class="relative text-gray-600 focus-within:text-gray-400">
                        <span class="absolute inset-y-0 left-0 flex items-center pl-2">
                            <svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" class="w-6 h-6 text-gray-500"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
                        </span>
                        <input aria-placeholder="Busca tus amigos o contacta nuevos" placeholder="Busca tus amigos"
                        class="py-2 pl-10 block w-full rounded bg-gray-100 outline-none focus:text-gray-700" type="search" name="search" required autocomplete="search" />
                    </div>
                </div>

                <ul class="overflow-auto" style="height: 500px;">
                    <h2 class="ml-2 mb-2 text-gray-600 text-lg my-2">Chats</h2>
                    <li>
                        <a class="hover:bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                            <img class="h-10 w-10 rounded-full object-cover"
                            src="https://images.pexels.com/photos/837358/pexels-photo-837358.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                            alt="username" />
                            <div class="w-full pb-2">
                                <div class="flex justify-between">
                                    <span class="block ml-2 font-semibold text-base text-gray-600 ">Jhon C</span>
                                    <span class="block ml-2 text-sm text-gray-600">5 minutes</span>
                                </div>
                                <span class="block ml-2 text-sm text-gray-600">Hello world!!</span>
                            </div>
                        </a>
                        <a class="bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                            <img class="h-10 w-10 rounded-full object-cover"
                            src="https://images.pexels.com/photos/3777931/pexels-photo-3777931.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                            alt="username" />
                            <div class="w-full pb-2">
                                <div class="flex justify-between">
                                    <span class="block ml-2 font-semibold text-base text-gray-600 ">Eduard</span>
                                    <span class="block ml-2 text-sm text-gray-600">15 minutes</span>
                                </div>
                                <span class="block ml-2 text-sm text-gray-600">I am fine</span>
                            </div>
                        </a>
                        <a class="hover:bg-gray-100 border-b border-gray-300 px-3 py-2 cursor-pointer flex items-center text-sm focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
                            <img class="h-10 w-10 rounded-full object-cover"
                            src="https://images.pexels.com/photos/6238133/pexels-photo-6238133.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                            alt="username" />
                            <div class="w-full pb-2">
                                <div class="flex justify-between">
                                    <span class="block ml-2 font-semibold text-base text-gray-600 ">Celia</span>
                                    <span class="block ml-2 text-sm text-gray-600">1 hour</span>
                                </div>
                                <span class="block ml-2 text-sm text-gray-600">Last message</span>
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="col-span-2 bg-white">
                <div class="w-full">
                    <div class="flex items-center border-b border-gray-300 pl-3 py-3">
                        <img class="h-10 w-10 rounded-full object-cover"
                        src="https://images.pexels.com/photos/3777931/pexels-photo-3777931.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
                        alt="username" />
                        <span class="block ml-2 font-bold text-base text-gray-600">Eduard</span>
                        <span class="connected text-green-500 ml-2" >
                            <svg width="6" height="6">
                                <circle cx="3" cy="3" r="3" fill="currentColor"></circle>
                            </svg>
                        </span>
                    </div>
                    <div id="chat" class="w-full overflow-y-auto p-10 relative" style="height: 700px;" ref="toolbarChat">
                        <ul>
                            <li class="clearfix2">
                                <div class="w-full flex justify-start">
                                    <div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
                                        <span class="block">Hello bro</span>
                                        <span class="block text-xs text-right">10:30pm</span>
                                    </div>
                                </div>
                                <div class="w-full flex justify-end" >
                                    <div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
                                        <span class="block">Hello</span>
                                        <span class="block text-xs text-left">10:32pm</span>
                                    </div>
                                </div>
                                <div class="w-full flex justify-end" >
                                    <div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
                                        <span class="block">how are you?</span>
                                        <span class="block text-xs text-left">10:32pm</span>
                                    </div>
                                </div>
                                <div class="w-full flex justify-start">
                                    <div class="bg-gray-100 rounded px-5 py-2 my-2 text-gray-700 relative" style="max-width: 300px;">
                                        <span class="block">I am fine</span>
                                        <span class="block text-xs text-right">10:42pm</span>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>

                    <div class="w-full py-3 px-3 flex items-center justify-between border-t border-gray-300">
                        <button class="outline-none focus:outline-none">
                            <svg class="text-gray-400 h-6 w-6" 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 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
                            </svg>
                        </button>
                        <button class="outline-none focus:outline-none ml-1">
                            <svg class="text-gray-400 h-6 w-6" 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="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />
                            </svg>
                        </button>

                        <input aria-placeholder="Escribe un mensaje aquí" placeholder="Escribe un mensaje aquí"
                            class="py-2 mx-3 pl-5 block w-full rounded-full bg-gray-100 outline-none focus:text-gray-700" type="text" name="message" required/>

                        <button class="outline-none focus:outline-none" type="submit">
                            <svg class="text-gray-400 h-7 w-7 origin-center transform rotate-90" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
                                <path d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z" />
                            </svg>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

How to make a Example Chat 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 make a Example Chat component

  • w-screen
  • grid
  • grid-cols-3
  • min-w-full
  • bg-white
  • border-r
  • border-gray-300
  • my-3
  • mx-3
  • relative
  • text-gray-600
  • focus-within:text-gray-400
  • absolute
  • left-0
  • flex
  • pl-2
  • w-6
  • h-6
  • text-gray-500
  • py-2
  • pl-10
  • block
  • w-full
  • bg-gray-100
  • focus:text-gray-700
  • overflow-auto
  • ml-2
  • mb-2
  • text-lg
  • my-2
  • hover:bg-gray-100
  • border-b
  • px-3
  • text-sm
  • focus:border-gray-300
  • h-10
  • w-10
  • pb-2
  • text-base
  • pl-3
  • py-3
  • text-green-500
  • overflow-y-auto
  • p-10
  • justify-start
  • px-5
  • text-gray-700
  • text-xs
  • text-right
  • text-left
  • border-t
  • text-gray-400
  • ml-1
  • pl-5
  • h-7
  • w-7

56 steps to make a Example Chat component with Tailwind CSS

  1. Use w-screen to make an element span the entire width of the viewport.

  2. Use grid to create a grid container.

  3. Use grid to create a grid container.

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

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

  6. Control the border color of an element to r using the border-r utilities.

  7. Control the border color of an element to gray-300 using the border-gray-300 utilities.

  8. Control the vertical margin of an element to 0.75rem using the my-3 utilities.

  9. Control the horizontal margin of an element to 0.75rem using the mx-3 utilities.

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

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

  12. Control the text color of an element to gray-400undefined using the focus-within:text-gray-400 utilities.

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

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

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

  16. Set the left padding of the element to 0.5rem using the pl-2 utilities class

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

  18. Use h-6 to set an element to a fixed height(1.5rem).

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

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

  21. Set the left padding of the element to 2.5rem using the pl-10 utilities class

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

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

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

  25. Control the text color of an element to gray-700 on focus using the focus:text-gray-700 utilities.

  26. Use overflow-auto to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike .overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.

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

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

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

  30. Control the vertical margin of an element to 0.5rem using the my-2 utilities.

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

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

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

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

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

  36. Use h-10 to set an element to a fixed height(2.5rem).

  37. Use w-10 to set an element to a fixed width(2.5rem).

  38. Control the padding on bottom side of an element to 0.5rem using the pb-2 utilities.

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

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

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

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

  43. Use overflow-y-auto to allow vertical scrolling if needed.

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

  45. Use justify-start to justify items against the start of the container’s main axis.

  46. Control the horizontal padding of an element to 1.25rem using the px-5 utilities.

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

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

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

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

  51. Control the border color of an element to t using the border-t utilities.

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

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

  54. Set the left padding of the element to 1.25rem using the pl-5 utilities class

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

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

Conclusion

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