Published on

The Ninja Guide To How To Make A Notification With Tailwind CSS Better

Tags
Notification

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 Notification ui component

Notification with icons

Why use Tailwind CSS to make a Notification ui component?

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

The preview of Notification ui component

Free download of the Notification's source code

The source code of Notification ui component

<div class="flex w-full px-6 py-4 my-2 rounded-xl shadow-md font-semibold text-md bg-yellow-50 text-yellow-800"><span class="h-6 w-6 mr-4"><svg 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 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path></svg></span>This is a message for you.<button class="h-6 w-6 ml-auto"><svg 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="M6 18L18 6M6 6l12 12"></path></svg></button></div>

How to make a Notification with Tailwind CSS?

Install tailwind css of verion 2.1.4

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

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

All the unility class needed to make a Notification component

  • flex
  • w-full
  • px-6
  • py-4
  • my-2
  • text-md
  • bg-yellow-50
  • text-yellow-800
  • h-6
  • w-6
  • mr-4
  • ml-auto

12 steps to make a Notification component with Tailwind CSS

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

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

  3. Control the horizontal padding of an element to 1.5rem using the px-6 utilities.

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

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

  6. Control the text color of an element to md using the text-md utilities.

  7. Control the background color of an element to yellow-50 using the bg-yellow-50 utilities.

  8. Control the text color of an element to yellow-800 using the text-yellow-800 utilities.

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

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

  11. Control the margin on right side of an element to 1rem using the mr-4 utilities.

  12. Control the margin on left side of an element to auto using the ml-auto utilities.

Conclusion

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