- Published on
Surprisingly Effective Ways To Create A Facebook Toast With Tailwind CSS

- What is Tailwind CSS?
- The description of Facebook Toast ui component
- Why use Tailwind CSS to make a Facebook Toast ui component?
- The preview of Facebook Toast ui component
- The source code of Facebook Toast ui component
- How to make a Facebook Toast with Tailwind CSS?
- Install tailwind css of verion 2.0.2
- All the unility class needed to make a Facebook Toast component
- 40 steps to make a Facebook Toast component with Tailwind CSS
- Conclusion
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
Use
relative
to position an element according to the normal flow of the document.Set the minimum width/height of an element using the
min-h-screen
utilities.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the vertical padding of an element to 1.5rem using the
py-6
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the vertical padding of an element to 3rem at only small screen sizes using the
sm:py-12
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the background color of an element to gradient-to-tl using the
bg-gradient-to-tl
utilities.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to gradient-to-tr using the
hover:bg-gradient-to-tr
utilities on hover.Control the margin on right side of an element to 0.5rem using the
mr-2
utilities.Use
w-5
to set an element to a fixed width(1.25rem).Use
h-6
to set an element to a fixed height(1.5rem).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.Use the
bottom-5
utilities to set the bottom position of a positioned element to 1.25rem.Use the
left-8
utilities to set the left position of a positioned element to 2rem.Control the background color of an element to white using the
bg-white
utilities.Use
w-64
to set an element to a fixed width(16rem).Use
w-full
to set an element to a 100% based width.Control the text color of an element to sm using the
text-sm
utilities.Use
w-6
to set an element to a fixed width(1.5rem).Control the background color of an element to gray-200 using the
bg-gray-200
utilities.Control the background color of an element to gray-300 using the
hover:bg-gray-300
utilities on hover.Use
w-4
to set an element to a fixed width(1rem).Use
h-4
to set an element to a fixed height(1rem).Use
justify-start
to justify items against the start of the container’s main axis.Use
flex
to create a block-level flex container.Use
w-14
to set an element to a fixed width(3.5rem).Use
h-14
to set an element to a fixed height(3.5rem).Use the
-bottom-1
utilities to set the bottom position of a positioned element to -0.25rem.Use the
-right-2
utilities to set the right position of a positioned element to -0.5rem.Use
h-7
to set an element to a fixed height(1.75rem).Use
w-7
to set an element to a fixed width(1.75rem).Control the background color of an element to gradient-to-t using the
bg-gradient-to-t
utilities.Use
h-20
to set an element to a fixed height(5rem).Use
overflow-hidden
to clip any content within an element that overflows the bounds of that element.Control the text color of an element to blue-600 using the
text-blue-600
utilities.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.