Published on

Surprisingly Effective Ways To Create A Facebook Toast With Tailwind CSS

Facebook Toast

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 Facebook Toast ui component

Toast facebook using tailwindcss

Why use Tailwind CSS to make a Facebook Toast ui component?

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

The preview of Facebook Toast ui component

Free download of the Facebook Toast's source code

The source code of Facebook Toast ui component

<style>
  .clamp-3 {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
  .to-cyan-400 {
    --tw-gradient-to: #22d3ee;
    }
 .via-cyan-500 {
    --tw-gradient-stops: var(--tw-gradient-from), #06b6d4, var(--tw-gradient-to, rgba(6, 182, 212, 0));
    }
</style>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>

<div x-data="{openNotify: false, open1: false, open2: false}" class="relative min-h-screen bg-gray-100 py-6 flex flex-col justify-center sm:py-12 items-center">
  <div>
    <button @click="openNotify = true, open1 = true, open2 = true" class="px-3 py-2 flex justify-center items-center bg-gradient-to-tl from-blue-500 to-cyan-400 rounded text-white focus:outline-none font-semibold shadow hover:transition-colors hover:bg-gradient-to-tr transform transition hover:scale-110 ease-out duration-300 hover:shadow-md">
      <div class="mr-2">
        <svg class="w-5 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
          <path d="M10 12a2 2 0 100-4 2 2 0 000 4z"></path><path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"></path>
        </svg>
      </div>
      Show
    </button>
  </div>
  <div x-cloak x-show="openNotify" x-transition:enter="transition ease-out duration-200"
    x-transition:enter-start="opacity-0 transform scale-90"
    x-transition:enter-end="opacity-100 transform scale-100"
    x-transition:leave="transition ease-in duration-200"
    x-transition:leave-start="opacity-100 transform scale-100"
    x-transition:leave-end="opacity-0 transform scale-90"
    class="absolute bottom-5 left-8 flex flex-col space-y-2">
    <div 
      x-cloak x-show="open1"
      x-transition:leave="transition ease-in duration-300"
      x-transition:leave-start="opacity-100 transform scale-100"
      x-transition:leave-end="opacity-0 transform scale-90"
      class="bg-white cursor-pointer shadow rounded-lg px-3 py-2 w-64 space-y-2">

      <!-- Header -->
      <div class="flex justify-between items-center w-full">
        <div class="font-semibold text-sm">
          Notifikasi Baru
        </div>
        <div @click="open1 = !open1" class="h-6 w-6 flex justify-center items-center bg-gray-200 rounded-full cursor-pointer hover:bg-gray-300">
          <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
        </div>
      </div>
      <!-- Content -->
      <div class="flex justify-start items-start space-x-4">
        <div class="relative flex flex-shrink-0">
          <img src="https://images.unsplash.com/photo-1582789991349-8f8e6eb15308?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MjN8fGFuaW1lfGVufDB8fDB8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Meow" class="w-14 h-14 rounded-full object-cover">
        <div class="absolute -bottom-1 -right-2 h-7 w-7 bg-gradient-to-t from-blue-600 via-cyan-500 to-cyan-400 rounded-full text-white flex justify-center items-start">
          <div class="">
            <svg class="w-5 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v3h8v-3zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-3a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v3h-3zM4.75 12.094A5.973 5.973 0 004 15v3H1v-3a3 3 0 013.75-2.906z"></path></svg>
          </div>
        </div>
        </div>
        <div class="flex flex-col h-20 overflow-hidden">
          <div class="overflow-ellipsis overflow-hidden text-sm">
            <div class="clamp-3 leading-tight ">
              <b class="font-semibold">Hasan Muhammad</b> Menambahkann 2 foto di <b class="font-semibold">Tailwind CSS Indonesia</b>
            </div>
          </div>
          <div class="text-blue-600 font-semibold text-xs leading-loose">15 menit yang lalu</div>
        </div>
      </div>
    </div>

    
    <div 
      x-cloak x-show="open2"
      x-transition:leave="transition ease-in duration-300"
      x-transition:leave-start="opacity-100 transform scale-100"
      x-transition:leave-end="opacity-0 transform scale-90"
      class="bg-white cursor-pointer shadow rounded-lg px-3 py-2 w-64 space-y-2">

      <!-- Header -->
      <div class="flex justify-between items-center w-full">
        <div class="font-semibold text-sm">
          Notifikasi Baru
        </div>
        <div @click="open2 = !open2" class="h-6 w-6 flex justify-center items-center bg-gray-200 rounded-full cursor-pointer hover:bg-gray-300">
          <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
        </div>
      </div>
      <!-- Content -->
      <div class="flex justify-start items-start space-x-4">
        <div class="relative flex flex-shrink-0">
          <img src="https://images.unsplash.com/photo-1582789991349-8f8e6eb15308?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MjN8fGFuaW1lfGVufDB8fDB8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Meow" class="w-14 h-14 rounded-full object-cover">
        <div class="absolute -bottom-1 -right-2 h-7 w-7 bg-gradient-to-t from-blue-600 via-cyan-500 to-cyan-400 rounded-full text-white flex justify-center items-start">
          <div class="">
            <svg class="w-5 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v3h8v-3zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-3a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v3h-3zM4.75 12.094A5.973 5.973 0 004 15v3H1v-3a3 3 0 013.75-2.906z"></path></svg>
          </div>
        </div>
        </div>
        <div class="flex flex-col h-20 overflow-hidden">
          <div class="overflow-ellipsis overflow-hidden text-sm">
            <div class="clamp-3 leading-tight ">
              <b class="font-semibold">Hasan Muhammad</b> Menambahkann 2 foto di <b class="font-semibold">Tailwind CSS Indonesia</b>
            </div>
          </div>
          <div class="text-blue-600 font-semibold text-xs leading-loose">15 menit yang lalu</div>
        </div>
      </div>
    </div>
    
  </div>
  
</div>

How to make a Facebook Toast with Tailwind CSS?

Install tailwind css of verion 2.0.2

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

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

All the unility class needed to make a Facebook Toast component

  • relative
  • min-h-screen
  • bg-gray-100
  • py-6
  • flex
  • flex-col
  • sm:py-12
  • px-3
  • py-2
  • bg-gradient-to-tl
  • text-white
  • hover:bg-gradient-to-tr
  • mr-2
  • w-5
  • h-6
  • absolute
  • bottom-5
  • left-8
  • bg-white
  • w-64
  • w-full
  • text-sm
  • w-6
  • bg-gray-200
  • hover:bg-gray-300
  • w-4
  • h-4
  • justify-start
  • flex-shrink-0
  • w-14
  • h-14
  • -bottom-1
  • -right-2
  • h-7
  • w-7
  • bg-gradient-to-t
  • h-20
  • overflow-hidden
  • text-blue-600
  • text-xs

40 steps to make a Facebook Toast component with Tailwind CSS

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

  2. Set the minimum width/height of an element using the min-h-screen utilities.

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

  4. Control the vertical padding of an element to 1.5rem using the py-6 utilities.

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

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

  7. Control the vertical padding of an element to 3rem at only small screen sizes using the sm:py-12 utilities.

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

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

  10. Control the background color of an element to gradient-to-tl using the bg-gradient-to-tl utilities.

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

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

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

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

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

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

  17. Use the bottom-5 utilities to set the bottom position of a positioned element to 1.25rem.

  18. Use the left-8 utilities to set the left position of a positioned element to 2rem.

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

  20. Use w-64 to set an element to a fixed width(16rem).

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

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

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

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

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

  26. Use w-4 to set an element to a fixed width(1rem).

  27. Use h-4 to set an element to a fixed height(1rem).

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

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

  30. Use w-14 to set an element to a fixed width(3.5rem).

  31. Use h-14 to set an element to a fixed height(3.5rem).

  32. Use the -bottom-1 utilities to set the bottom position of a positioned element to -0.25rem.

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

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

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

  36. Control the background color of an element to gradient-to-t using the bg-gradient-to-t utilities.

  37. Use h-20 to set an element to a fixed height(5rem).

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

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

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

Conclusion

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