Published on

The Ninja Guide To How To Build A Notifications With Tailwind CSS Better

Tags
Notifications

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

Notifications card

Why use Tailwind CSS to create a Notifications ui component?

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

The preview of Notifications ui component

Free download of the Notifications's source code

The source code of Notifications ui component

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

<style>
body {
  background-image: linear-gradient( 109.6deg,  rgba(223,234,247,1) 11.2%, rgba(244,248,252,1) 61.1% );
  min-width: 100vw;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}



.rounded-xl{
  border-radius: 1rem;
}

.data-connection-icon{transform: rotate(270deg); width: 24px;}

.slider-wrapper{
  height: 1rem;
  position: relative;
  z-index: 1;
}
.slider-wrapper::before, .slider-wrapper::after{
  position: absolute;
  top: 45%;
  transform:  translateY(-50%);
  z-index: 2;
}

.slider-wrapper::before{color: #000; left: 8px; content: "-";}

.slider-wrapper::after{color: #fff; right: 8px; content: "+";}

.slider-pointer{
  height: 1.2rem;
  position: relative;
  z-index: 1;
}

.material-icons.md-14 { font-size: 14px; }
.material-icons.md-20 { font-size: 20px; }
.material-icons.md-24 { font-size: 24px; }
</style>




<div class="max-w-sm rounded-xl mb-4 overflow-hidden shadow-lg bg-gray-900 text-white">
  <div class="px-6 py-4 flex items-center justify-between">
    <div class="flex items-center">
      <b class="text-xs mr-2">09:00</b>
      <small class="text-xs">Tue, Aug 7</small>
    </div>
    <div class="flex items-center">
      <span class="material-icons md-14 mr-1">
        signal_wifi_4_bar
      </span>
      <span class="material-icons md-14 mr-1">
        alarm
      </span>
      <span class="material-icons md-14 mr-1">
        battery_full
      </span>
      <span class="text-xs">100%</span>
    </div>
  </div>
  <div class="px-6 py-4 flex items-center justify-between">
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-gray-200 mr-2">
      <span class="material-icons text-gray-900">
        signal_wifi_4_bar
      </span>
    </div>
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-gray-200 mr-2">
      <span class="material-icons md-24 text-gray-900 data-connection-icon">
        sync_alt
      </span>
    </div>
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-red-600 mr-2">
      <span class="material-icons text-gray-900">
        volume_off
      </span>
    </div>
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-gray-800 mr-2">
      <span class="material-icons">
        highlight
      </span>
    </div>
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-gray-800 mr-2">
      <span class="material-icons">
        bluetooth_disabled
      </span>
    </div>
    <div class="flex items-center justify-center rounded-full h-12 w-12 bg-gray-800">
      <span class="material-icons">
        cast
      </span>
    </div>
  </div>
  <div class="px-6 py-4 flex items-center justify-between">
    <div class="bg-gray-700 w-screen rounded-lg flex items-center slider-wrapper" style="">
     <div class="bg-gray-300 w-1/2 rounded-lg flex slider-pointer" style="">
      </div>
    </div>
  </div>
  <div class="px-6 py-4 flex items-center justify-between">
    <div class="flex items-center ">
      <span class="material-icons md-20 mr-1">
        signal_cellular_4_bar
      </span>
      <span class="text-sm">Fi Network</span>
      
    </div>
    <div class="flex items-center ">
      <span class="material-icons md-20 mr-3">
        search
      </span>
      <span class="material-icons md-20 mr-3">
        settings
      </span>
      <span class="material-icons md-20">
        account_circle
      </span>
    </div>
  </div>
</div>
<span class="font-bold">No notifications</span>

How to create a Notifications with Tailwind CSS?

Install tailwind css of verion 1.2.0

Use the link html tag to import the stylesheet of Tailwind CSS of the version 1.2.0

<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">

All the unility class needed to create a Notifications component

  • max-w-sm
  • mb-4
  • overflow-hidden
  • bg-gray-900
  • text-white
  • px-6
  • py-4
  • flex
  • text-xs
  • mr-2
  • mr-1
  • h-12
  • w-12
  • bg-gray-200
  • text-gray-900
  • bg-red-600
  • bg-gray-800
  • bg-gray-700
  • w-screen
  • bg-gray-300
  • w-1/2
  • text-sm
  • mr-3

23 steps to create a Notifications component with Tailwind CSS

  1. Set the maximum width/height of an element using the max-w-sm utilities.

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

  3. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  4. Control the background color of an element to gray-900 using the bg-gray-900 utilities.

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

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

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

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

  9. Control the text color of an element to xs using the text-xs utilities.

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

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

  12. Use h-12 to set an element to a fixed height(3rem).

  13. Use w-12 to set an element to a fixed width(3rem).

  14. Control the background color of an element to gray-200 using the bg-gray-200 utilities.

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

  16. Control the background color of an element to red-600 using the bg-red-600 utilities.

  17. Control the background color of an element to gray-800 using the bg-gray-800 utilities.

  18. Control the background color of an element to gray-700 using the bg-gray-700 utilities.

  19. Use w-screen to make an element span the entire width of the viewport.

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

  21. Use w-1/2 to set an element to a fixed width(1/2).

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

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

Conclusion

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