Published on

How to Make A Free Tailwind CSS Alert Component With Tailwind CSS?

Tags
Free Tailwind CSS Alert Component

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 Free Tailwind CSS Alert Component ui component

Tailwind alerts are dialogue boxes, also known as toast messages. find more free and premium tailwind css components at www.tailwinduikit.com

Why use Tailwind CSS to create a Free Tailwind CSS Alert Component ui component?

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

The preview of Free Tailwind CSS Alert Component ui component

Free download of the Free Tailwind CSS Alert Component's source code

The source code of Free Tailwind CSS Alert Component ui component

<dh-component>
<!--- more free and premium Tailwind CSS components at https://tailwinduikit.com/ --->
            <!-- Code block starts -->
            <div class="flex items-center justify-center px-4">
                <div role="alert" id="alert" class="transition duration-150 ease-in-out w-full lg:w-11/12 mx-auto bg-white dark:bg-gray-800 shadow rounded flex flex-col py-4 md:py-0 items-center md:flex-row justify-between">
                    <div class="flex flex-col items-center md:flex-row">
                        <div class="mr-3 p-4 bg-yellow-400 rounded md:rounded-tr-none md:rounded-br-none text-white">
                            <svg tabindex="0" role="alert" aria-label="warning" class="focus:outline-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="22" height="22" fill="currentColor">
                                <path class="heroicon-ui" d="M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20zm0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16zm0 9a1 1 0 0 1-1-1V8a1 1 0 0 1 2 0v4a1 1 0 0 1-1 1zm0 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2z" />
                            </svg>
                        </div>
                        <p class="mr-2 text-base font-bold text-gray-800 dark:text-gray-100 mt-2 md:my-0">Warning</p>
                        <div class="h-1 w-1 bg-gray-300 dark:bg-gray-700 rounded-full mr-2 hidden xl:block"></div>
                        <p class="text-sm lg:text-base dark:text-gray-400 text-gray-600 lg:pt-1 xl:pt-0 sm:mb-0 mb-2 text-center sm:text-left">Hurricane warning in this area. Please check local media and authorities-NWS</p>
                    </div>
                    <div class="flex xl:items-center lg:items-center sm:justify-end justify-center pr-4">
                        <button class="focus:outline-none focus:text-indigo-400 hover:text-indigo-400 text-sm mr-4 font-bold cursor-pointer text-indigo-700 dark:text-indigo-600">Details</button>
                        <button class="focus:outline-none focus:text-gray-400 hover:text-gray-400 text-sm cursor-pointer text-gray-600 dark:text-gray-400" onclick="closeAlert()">Dismiss</button>
                    </div>
                </div>
            </div>
            <!-- Code block ends -->
        </dh-component>
        <script>var Alert = document.getElementById("alert");
var close = document.getElementById("close-modal");
Alert.style.transform = "translateY(0%)";
function closeAlert() {
  Alert.style.transform = "translateY(-200%)";
  setTimeout(function () {
    Alert.style.transform = "translateY(0%)";
  }, 1000);
}
</script>

How to create a Free Tailwind CSS Alert Component with Tailwind CSS?

Install tailwind css of verion 2.2.19

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

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

All the unility class needed to create a Free Tailwind CSS Alert Component component

  • flex
  • px-4
  • w-full
  • lg:w-11/12
  • mx-auto
  • bg-white
  • dark:bg-gray-800
  • flex-col
  • py-4
  • md:py-0
  • md:flex-row
  • mr-3
  • p-4
  • bg-yellow-400
  • text-white
  • mr-2
  • text-base
  • text-gray-800
  • dark:text-gray-100
  • mt-2
  • md:my-0
  • h-1
  • w-1
  • bg-gray-300
  • dark:bg-gray-700
  • hidden
  • xl:block
  • text-sm
  • lg:text-base
  • dark:text-gray-400
  • text-gray-600
  • lg:pt-1
  • xl:pt-0
  • sm:mb-0
  • mb-2
  • text-center
  • sm:text-left
  • pr-4
  • focus:text-indigo-400
  • hover:text-indigo-400
  • mr-4
  • text-indigo-700
  • dark:text-indigo-600
  • focus:text-gray-400
  • hover:text-gray-400

45 steps to create a Free Tailwind CSS Alert Component component with Tailwind CSS

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

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

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

  4. Use lg:w-11/12 to set an element to a fixed width(11/12) at only large screen sizes.

  5. Control the horizontal margin of an element to auto using the mx-auto utilities.

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

  7. Control the background color of an element to gray-800 using the dark:bg-gray-800 utilities in dark theme.

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

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

  10. Control the vertical padding of an element to 0rem at only medium screen sizes using the md:py-0 utilities.

  11. Use flex to create a block-level flex container at only medium screen sizes.

  12. Control the margin on right side of an element to 0.75rem using the mr-3 utilities.

  13. Control the padding on all sides of an element to 1rem using the p-4 utilities.

  14. Control the background color of an element to yellow-400 using the bg-yellow-400 utilities.

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

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

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

  18. Control the text color of an element to gray-800 using the text-gray-800 utilities.

  19. Control the text color of an element to gray-100 in dark theme using the dark:text-gray-100 utilities.

  20. Control the margin on top side of an element to 0.5rem using the mt-2 utilities.

  21. Control the vertical margin of an element to 0rem at only medium screen sizes using the md:my-0 utilities.

  22. Use h-1 to set an element to a fixed height(0.25rem).

  23. Use w-1 to set an element to a fixed width(0.25rem).

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

  25. Control the background color of an element to gray-700 using the dark:bg-gray-700 utilities in dark theme.

  26. Use hidden to set an element to display: none and remove it from the page layout.

  27. Use inline utilities to put the element on its own line and fill its parent at only extremely large screen sizes.

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

  29. Control the text color of an element to base at only large screen sizes using the lg:text-base utilities.

  30. Control the text color of an element to gray-400 in dark theme using the dark:text-gray-400 utilities.

  31. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  32. Control the padding on top side of an element to 0.25rem at only large screen sizes using the lg:pt-1 utilities.

  33. Control the padding on top side of an element to 0rem at only extremely large screen sizes using the xl:pt-0 utilities.

  34. Control the margin on bottom side of an element to 0rem at only small screen sizes using the sm:mb-0 utilities.

  35. Control the margin on bottom side of an element to 0.5rem using the mb-2 utilities.

  36. Control the text color of an element to center using the text-center utilities.

  37. Control the text color of an element to left at only small screen sizes using the sm:text-left utilities.

  38. Control the padding on right side of an element to 1rem using the pr-4 utilities.

  39. Control the text color of an element to indigo-400 on focus using the focus:text-indigo-400 utilities.

  40. Control the text color of an element to indigo-400 on hover using the hover:text-indigo-400 utilities.

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

  42. Control the text color of an element to indigo-700 using the text-indigo-700 utilities.

  43. Control the text color of an element to indigo-600 in dark theme using the dark:text-indigo-600 utilities.

  44. Control the text color of an element to gray-400 on focus using the focus:text-gray-400 utilities.

  45. Control the text color of an element to gray-400 on hover using the hover:text-gray-400 utilities.

Conclusion

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