- Published on
Surprisingly Effective Ways To Make A Notifications Dropdown With Tailwind CSS

- What is Tailwind CSS?
- The description of Notifications dropdown ui component
- Why use Tailwind CSS to build a Notifications dropdown ui component?
- The preview of Notifications dropdown ui component
- The source code of Notifications dropdown ui component
- How to build a Notifications dropdown with Tailwind CSS?
- Install tailwind css of verion 1.7.0
- All the unility class needed to build a Notifications dropdown component
- 35 steps to build a Notifications dropdown 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 Notifications dropdown ui component
Why use Tailwind CSS to build a Notifications dropdown ui component?
- It can make the building process of Notifications dropdown ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Notifications dropdown component file.
The preview of Notifications dropdown ui component
Free download of the Notifications dropdown's source code
The source code of Notifications dropdown ui component
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
<div class="flex justify-center h-screen">
<div x-data="{ dropdownOpen: true }" class="relative my-32">
<button @click="dropdownOpen = !dropdownOpen" class="relative z-10 block rounded-md bg-white p-2 focus:outline-none">
<svg class="h-5 w-5 text-gray-800" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z" />
</svg>
</button>
<div x-show="dropdownOpen" @click="dropdownOpen = false" class="fixed inset-0 h-full w-full z-10"></div>
<div x-show="dropdownOpen" class="absolute right-0 mt-2 bg-white rounded-md shadow-lg overflow-hidden z-20" style="width:20rem;">
<div class="py-2">
<a href="#" class="flex items-center px-4 py-3 border-b hover:bg-gray-100 -mx-2">
<img class="h-8 w-8 rounded-full object-cover mx-1" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="avatar">
<p class="text-gray-600 text-sm mx-2">
<span class="font-bold" href="#">Sara Salah</span> replied on the <span class="font-bold text-blue-500" href="#">Upload Image</span> artical . 2m
</p>
</a>
<a href="#" class="flex items-center px-4 py-3 border-b hover:bg-gray-100 -mx-2">
<img class="h-8 w-8 rounded-full object-cover mx-1" src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80" alt="avatar">
<p class="text-gray-600 text-sm mx-2">
<span class="font-bold" href="#">Slick Net</span> start following you . 45m
</p>
</a>
<a href="#" class="flex items-center px-4 py-3 border-b hover:bg-gray-100 -mx-2">
<img class="h-8 w-8 rounded-full object-cover mx-1" src="https://images.unsplash.com/photo-1450297350677-623de575f31c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="avatar">
<p class="text-gray-600 text-sm mx-2">
<span class="font-bold" href="#">Jane Doe</span> Like Your reply on <span class="font-bold text-blue-500" href="#">Test with TDD</span> artical . 1h
</p>
</a>
<a href="#" class="flex items-center px-4 py-3 hover:bg-gray-100 -mx-2">
<img class="h-8 w-8 rounded-full object-cover mx-1" src="https://images.unsplash.com/photo-1580489944761-15a19d654956?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=398&q=80" alt="avatar">
<p class="text-gray-600 text-sm mx-2">
<span class="font-bold" href="#">Abigail Bennett</span> start following you . 3h
</p>
</a>
</div>
<a href="#" class="block bg-gray-800 text-white text-center font-bold py-2">See all notifications</a>
</div>
</div>
</div>
How to build a Notifications dropdown with Tailwind CSS?
Install tailwind css of verion 1.7.0
Use the link
html tag to import the stylesheet of Tailwind CSS of the version 1.7.0
<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
All the unility class needed to build a Notifications dropdown component
flex
h-screen
relative
my-32
z-10
block
bg-white
p-2
h-5
w-5
text-gray-800
fixed
h-full
w-full
absolute
right-0
mt-2
overflow-hidden
z-20
py-2
px-4
py-3
border-b
hover:bg-gray-100
-mx-2
h-8
w-8
mx-1
text-gray-600
text-sm
mx-2
text-blue-500
bg-gray-800
text-white
text-center
35 steps to build a Notifications dropdown component with Tailwind CSS
Use
flex
to create a block-level flex container.Use
h-screen
to make an element span the entire height of the viewport.Use
relative
to position an element according to the normal flow of the document.Control the vertical margin of an element to 8rem using the
my-32
utilities.Control the stack order (or three-dimensional positioning) of an element to 10 in Tailwind, regardless of order it has been displayed, using the
z-10
utilities.Use
inline
utilities to put the element on its own line and fill its parent.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 0.5rem using the
p-2
utilities.Use
h-5
to set an element to a fixed height(1.25rem).Use
w-5
to set an element to a fixed width(1.25rem).Control the text color of an element to gray-800 using the
text-gray-800
utilities.Use
fixed
to position an element relative to the browser window.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Use
w-full
to set an element to a 100% based width.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
right-0
utilities to set the right position of a positioned element to 0rem.Control the margin on top side of an element to 0.5rem using the
mt-2
utilities.Use
overflow-hidden
to clip any content within an element that overflows the bounds of that element.Control the stack order (or three-dimensional positioning) of an element to 20 in Tailwind, regardless of order it has been displayed, using the
z-20
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the vertical padding of an element to 0.75rem using the
py-3
utilities.Control the border color of an element to b using the
border-b
utilities.Control the background color of an element to gray-100 using the
hover:bg-gray-100
utilities on hover.Control the horizontal margin of an element to -0.5rem using the
-mx-2
utilities.Use
h-8
to set an element to a fixed height(2rem).Use
w-8
to set an element to a fixed width(2rem).Control the horizontal margin of an element to 0.25rem using the
mx-1
utilities.Control the text color of an element to gray-600 using the
text-gray-600
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the horizontal margin of an element to 0.5rem using the
mx-2
utilities.Control the text color of an element to blue-500 using the
text-blue-500
utilities.Control the background color of an element to gray-800 using the
bg-gray-800
utilities.Control the text color of an element to white using the
text-white
utilities.Control the text color of an element to center using the
text-center
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Notifications dropdown components, learn and follow along to implement your own components.