Published on

Most Effective Ways To Create A Fancy Buttons With Tailwind CSS

Fancy Buttons

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

Fancy buttons

Why use Tailwind CSS to build a Fancy Buttons ui component?

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

The preview of Fancy Buttons ui component

Free download of the Fancy Buttons's source code

The source code of Fancy Buttons ui component

<style>
@keyframes hue {
  0% {filter:hue-rotate(0deg);}
  100% {filter:hue-rotate(80deg);}
}

@keyframes translate {
  0% {transform:translate(0,0%);}
  100% {transform:translate(0,-75%);}
}

.active img {
  animation:hue 1.3s infinite linear alternate;    
}

.loading img{
  animation:translate 1.3s linear infinite alternate;
  opacity:0.8;
  filter:contrast(200%);
  box-shadow:none !important;
}

.button:hover img{
  transform:translate(0px ,-20px);
  /* filter:brightness(120%); */
}
.button{
  box-shadow:0px 0px 3px 1px gray;
}
.button:active{
  transform:scale(0.95);
  box-shadow:none !important;
}
.button img{
  filter:brightness(110%);
  transition:all 0.2s;
}

body{
    background:white;
}
</style>
<h1 class="text-xl mx-auto w-max my-5">Fancy Buttons</h1>


<div class="main w-max border flex p-5 mx-auto">
  <div class="button mr-2 select-none cursor-pointer w-max relative rounded-sm">
        <div class="pic overflow-hidden rounded-sm absolute w-full h-full">
          <img class="h-44 w-60" src="https://i.ibb.co/SJxDmYd/image.jpg">  
        </div>  
        <div class="text text-gray-600 top-0 font-bold relative p-2 px-4">Cold</div>    
  </div>
<!-- button end -->
  <div class="button loading mr-2 select-none cursor-pointer w-max relative rounded-sm">
        <div class="pic overflow-hidden rounded-sm absolute w-full h-full">
          <img class="h-44 w-60" src="https://i.ibb.co/LNmvXC8/image-1.jpg">  
        </div>  
        <div class="text text-gray-200 top-0 font-bold relative p-2 px-4">Heating...</div>    
  </div>
<!-- button end -->
  <div class="button mr-2 select-none cursor-pointer w-max relative rounded-sm">
        <div class="pic overflow-hidden rounded-sm absolute w-full h-full">
          <img class="h-44 w-60" src="https://i.ibb.co/mvcDDhM/image-3.jpg">  
        </div>  
        <div class="text text-gray-200 top-0 font-bold relative p-2 px-4">Orange</div>    
  </div>
<!-- button end -->
  <div class="button mr-2 select-none cursor-pointer w-max relative rounded-sm">
        <div class="pic overflow-hidden rounded-sm absolute w-full h-full">
          <img class="h-44 w-60" src="https://i.ibb.co/0Cx0GRg/image-5.jpg">  
        </div>  
        <div class="text text-gray-200 top-0 font-bold relative p-2 px-4">Steel</div>    
  </div>
<!-- button end -->
  <div class="button loading mr-2 select-none cursor-pointer w-max relative rounded-sm">
        <div class="pic overflow-hidden rounded-sm absolute w-full h-full">
          <img class="h-44 w-60" src="https://i.ibb.co/SJxDmYd/image.jpg">  
        </div>  
        <div class="text text-gray-700 top-0 font-bold relative p-2 px-4">Applying...</div>    
  </div>
<!-- button end -->
<!-- use loading and active class in button root -->


</div>

How to build a Fancy Buttons 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 Fancy Buttons component

  • text-xl
  • mx-auto
  • w-max
  • my-5
  • flex
  • p-5
  • mr-2
  • relative
  • overflow-hidden
  • absolute
  • w-full
  • h-full
  • h-44
  • w-60
  • text-gray-600
  • top-0
  • p-2
  • px-4
  • text-gray-200
  • text-gray-700

20 steps to build a Fancy Buttons component with Tailwind CSS

  1. Control the text color of an element to xl using the text-xl utilities.

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

  3. Use w-max to set an element to a fixed width(max).

  4. Control the vertical margin of an element to 1.25rem using the my-5 utilities.

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

  6. Control the padding on all sides of an element to 1.25rem using the p-5 utilities.

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

  8. Use relative to position an element according to the normal flow of the document.

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

  10. Use absolute to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.

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

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

  13. Use h-44 to set an element to a fixed height(11rem).

  14. Use w-60 to set an element to a fixed width(15rem).

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

  16. Use the top-0 utilities to set the top position of a positioned element to 0rem.

  17. Control the padding on all sides of an element to 0.5rem using the p-2 utilities.

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

  19. Control the text color of an element to gray-200 using the text-gray-200 utilities.

  20. Control the text color of an element to gray-700 using the text-gray-700 utilities.

Conclusion

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