Published on

6 Tips To Make A Tailwind Alerts With Tailwind CSS

Tags
Tailwind Alerts

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 Tailwind Alerts ui component

Simple and beautiful alerts with tailwind

Why use Tailwind CSS to make a Tailwind Alerts ui component?

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

The preview of Tailwind Alerts ui component

Free download of the Tailwind Alerts's source code

The source code of Tailwind Alerts ui component

<div class="flex flex-col gap-2">
    <div class="bg-blue-50 rounded text-blue-900 px-4 py-3" role="alert">
        <div class="flex">
            <div>
                <svg class="fill-current h-6 w-6 text-blue-500 mr-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM9 11V9h2v6H9v-4zm0-6h2v2H9V5z"/></svg></div>
            <div>
                <p class="text-sm text-blue-500">Lorem ipsum dolor sit amet, consectetur adip!.</p>
            </div>
        </div>
    </div>

    <div class="bg-green-50 rounded text-green-900 px-4 py-3" role="alert">
        <div class="flex">
            <div>
                <svg class="fill-current h-6 w-6 text-green-500 mr-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10s10-4.5 10-10S17.5 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m4.59-12.42L10 14.17l-2.59-2.58L6 13l4 4l8-8l-1.41-1.42z" /></svg>
            </div>
            <div>
                <p class="text-sm text-green-500">Lorem ipsum dolor sit amet, consectetur adip!.</p>
            </div>
        </div>
    </div>

    <div class="bg-yellow-50 rounded text-yellow-900 px-4 py-3" role="alert">
        <div class="flex">
            <div>
                <svg class="fill-current h-6 w-6 text-yellow-500 mr-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path d="M13 14h-2V9h2m0 9h-2v-2h2M1 21h22L12 2L1 21z"/></svg>
            </div>
            <div>
                <p class="text-sm text-yellow-500">Lorem ipsum dolor sit amet, consectetur adip!.</p>
            </div>
        </div>
    </div>
    <div class="bg-red-50 rounded text-red-900 px-4 py-3" role="alert">
        <div class="flex">
            <div>
                <svg class="fill-current h-6 w-6 text-red-500 mr-4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path d="M12 2c5.5 0 10 4.5 10 10s-4.5 10-10 10S2 17.5 2 12S6.5 2 12 2m0 2c-1.9 0-3.6.6-4.9 1.7l11.2 11.2c1-1.4 1.7-3.1 1.7-4.9c0-4.4-3.6-8-8-8m4.9 14.3L5.7 7.1C4.6 8.4 4 10.1 4 12c0 4.4 3.6 8 8 8c1.9 0 3.6-.6 4.9-1.7z" /></svg>
            </div>
            <div>
                <p class="text-sm text-red-500">Lorem ipsum dolor sit amet, consectetur adip!.</p>
            </div>
        </div>
    </div>
</div>
<!-- BUY ME A BEER AND HELP SUPPORT OPEN-SOURCE RESOURCES -->
<div class="flex items-end justify-end fixed bottom-0 right-0 mb-4 mr-4 z-10">
    <div>
        <a title="Buy me a beer" href="https://www.buymeacoffee.com/udiptaweb" target="_blank" class="block w-16 h-16 rounded-full transition-all shadow hover:shadow-lg transform hover:scale-110 hover:rotate-12">
            <img class="object-cover object-center w-full h-full rounded-full" src="https://i.pinimg.com/originals/60/fd/e8/60fde811b6be57094e0abc69d9c2622a.jpg"/>
        </a>
    </div>
</div>

How to make a Tailwind Alerts with Tailwind CSS?

Install tailwind css of verion 2.2.4

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

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

All the unility class needed to make a Tailwind Alerts component

  • flex
  • flex-col
  • gap-2
  • bg-blue-50
  • text-blue-900
  • px-4
  • py-3
  • h-6
  • w-6
  • text-blue-500
  • mr-4
  • text-sm
  • bg-green-50
  • text-green-900
  • text-green-500
  • bg-yellow-50
  • text-yellow-900
  • text-yellow-500
  • bg-red-50
  • text-red-900
  • text-red-500
  • fixed
  • bottom-0
  • right-0
  • mb-4
  • z-10
  • block
  • w-16
  • h-16
  • w-full
  • h-full

31 steps to make a Tailwind Alerts component with Tailwind CSS

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

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

  3. To specify the width between columns, you can use the gap-2 utilities.

  4. Control the background color of an element to blue-50 using the bg-blue-50 utilities.

  5. Control the text color of an element to blue-900 using the text-blue-900 utilities.

  6. Control the horizontal padding of an element to 1rem using the px-4 utilities.

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

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

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

  10. Control the text color of an element to blue-500 using the text-blue-500 utilities.

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

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

  13. Control the background color of an element to green-50 using the bg-green-50 utilities.

  14. Control the text color of an element to green-900 using the text-green-900 utilities.

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

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

  17. Control the text color of an element to yellow-900 using the text-yellow-900 utilities.

  18. Control the text color of an element to yellow-500 using the text-yellow-500 utilities.

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

  20. Control the text color of an element to red-900 using the text-red-900 utilities.

  21. Control the text color of an element to red-500 using the text-red-500 utilities.

  22. Use fixed to position an element relative to the browser window.

  23. Use the bottom-0 utilities to set the bottom position of a positioned element to 0rem.

  24. Use the right-0 utilities to set the right position of a positioned element to 0rem.

  25. Control the margin on bottom side of an element to 1rem using the mb-4 utilities.

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

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

  28. Use w-16 to set an element to a fixed width(4rem).

  29. Use h-16 to set an element to a fixed height(4rem).

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

  31. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

Conclusion

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