Published on

Learn How To Make A Small Modern Alerts With Tailwind CSS from the Pros

Tags
Small Modern 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 Small Modern Alerts ui component

3 alerts with different statuses. play.tailwindcss.com/tthwgopy7n

Why use Tailwind CSS to build a Small Modern Alerts ui component?

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

The preview of Small Modern Alerts ui component

Free download of the Small Modern Alerts's source code

The source code of Small Modern Alerts ui component

<div class="flex h-screen">
  <div class="m-auto">
    <div class="shadow-md p-4 flex flex-row rounded-lg">
      <div class="bg-red-500 inline-block rounded-lg p-1 mr-1"></div>
      <b class="p-1">Alert Title</b>
      <p class="p-1">This is a small alert!</p>
      <a class="h-5 w-5 text-gray-500 inline-block p-1">
        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
          <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
        </svg>
      </a>
    </div>
    <div class="shadow-md p-4 flex flex-row rounded-lg">
      <div class="bg-yellow-500 inline-block rounded-lg p-1 mr-1"></div>
      <b class="p-1">Alert Title</b>
      <p class="p-1">This is a small alert!</p>
      <a class="h-5 w-5 text-gray-500 inline-block p-1">
        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
          <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
        </svg>
      </a>
    </div>
    <div class="shadow-md p-4 flex flex-row rounded-lg">
      <div class="bg-green-500 inline-block rounded-lg p-1 mr-1"></div>
      <b class="p-1">Alert Title</b>
      <p class="p-1">This is a small alert!</p>
      <a class="h-5 w-5 text-gray-500 inline-block p-1">
        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
          <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
        </svg>
      </a>
    </div>
  </div>
</div>

How to build a Small Modern 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 build a Small Modern Alerts component

  • flex
  • h-screen
  • m-auto
  • p-4
  • flex-row
  • bg-red-500
  • inline-block
  • p-1
  • mr-1
  • h-5
  • w-5
  • text-gray-500
  • bg-yellow-500
  • bg-green-500

14 steps to build a Small Modern Alerts component with Tailwind CSS

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

  2. Use h-screen to make an element span the entire height of the viewport.

  3. Control the margin on all sides of an element to auto using the m-auto utilities.

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

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

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

  7. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

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

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

  10. Use h-5 to set an element to a fixed height(1.25rem).

  11. Use w-5 to set an element to a fixed width(1.25rem).

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

  13. Control the background color of an element to yellow-500 using the bg-yellow-500 utilities.

  14. Control the background color of an element to green-500 using the bg-green-500 utilities.

Conclusion

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