Published on

What You Need To Create A Color Selection With Tailwind CSS

color selection

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

Color option picker for motorcycle

Why use Tailwind CSS to build a color selection ui component?

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

The preview of color selection ui component

Free download of the color selection's source code

The source code of color selection ui component

<div class="min-h-screen bg-gray-50 py-6 flex flex-col justify-center relative overflow-hidden sm:py-12">
  <div class="relative px-6 pt-10 pb-8 bg-[#efedec] shadow-xl sm:max-w-lg sm:mx-auto rounded-xl sm:px-10">
    <div class="max-w-md mx-auto">
      <div class="divide-y divide-gray-400/50">
        <img src="https://www.harley-davidson.com/content/dam/h-d/images/product-images/bikes/motorcycle/2022/2022-softail-standard/2022-softail-standard-motorcycle-nav.jpg?impolicy=myresize&rw=500" />
        <div class="py-8 text-base flex justify-between">
            <p class="text-xl font-serif text-gray-900 opacity-75">Choose your pride</p>
            <div class="relative cursor-pointer gap-4 flex justify-center">
                <div class="w-8 h-8 bg-[#f6cda8] transition-all rounded-full block ring-[#f6cda8] hover:ring-2 ring-offset-1 " ></div>
                <div class="w-8 h-8 bg-[#d89d94] transition-all rounded-full block ring-[#d89d94] hover:ring-2 ring-offset-1 " ></div>
                <div class="w-8 h-8 bg-[#dd6b6c] transition-all rounded-full block ring-[#dd6b6c] hover:ring-2 ring-offset-1 " ></div>
                <div class="w-8 h-8 bg-[#875d71] transition-all rounded-full block ring-[#875d71] hover:ring-2 ring-offset-1 " ></div>
                <div class="w-8 h-8 bg-[#5b5b5b] transition-all rounded-full block ring-[#5b5b5b] hover:ring-2 ring-2 ring-offset-1 " ></div>
            </div>
        </div>
       <div class="divide-y divide-gray-400/50"></div>
    </div>
  </div>
</div>
<!-- color scheme from https://www.instagram.com/p/CXG6caosw0h/ -->
<style>
.bg\-\[\#f6cda8\]{
  background-color: #f6cda8
}
.bg\-\[\#d89d94\]{
  background-color: #d89d94
}
.bg\-\[\#dd6b6c\]{
  background-color: #dd6b6c
}
.bg\-\[\#875d71\]{
  background-color: #875d71
}
.bg\-\[\#5b5b5b\]{
  background-color: #5b5b5b
}
.bg\-\[\#efedec\]{
  background-color: #efedec
}
.divide-gray-400\/50 > :not([hidden]) ~ :not([hidden]) {
    border-color: rgb(156 163 175 / 0.5);
}
</style>

How to build a color selection 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 build a color selection component

  • min-h-screen
  • bg-gray-50
  • py-6
  • flex
  • flex-col
  • relative
  • overflow-hidden
  • sm:py-12
  • px-6
  • pt-10
  • pb-8
  • bg-[#efedec]
  • sm:max-w-lg
  • sm:mx-auto
  • sm:px-10
  • max-w-md
  • mx-auto
  • py-8
  • text-base
  • text-xl
  • text-gray-900
  • gap-4
  • w-8
  • h-8
  • bg-[#f6cda8]
  • block
  • bg-[#d89d94]
  • bg-[#dd6b6c]
  • bg-[#875d71]
  • bg-[#5b5b5b]

30 steps to build a color selection component with Tailwind CSS

  1. Set the minimum width/height of an element using the min-h-screen utilities.

  2. Control the background color of an element to gray-50 using the bg-gray-50 utilities.

  3. Control the vertical padding of an element to 1.5rem using the py-6 utilities.

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

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

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

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

  8. Control the vertical padding of an element to 3rem at only small screen sizes using the sm:py-12 utilities.

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

  10. Control the padding on top side of an element to 2.5rem using the pt-10 utilities.

  11. Control the padding on bottom side of an element to 2rem using the pb-8 utilities.

  12. Control the background color of an element to [#efedec] using the bg-[#efedec] utilities.

  13. Set the maximum width/height of an element using the sm:max-w-lg utilities at only small screen sizes.

  14. Control the horizontal margin of an element to auto at only small screen sizes using the sm:mx-auto utilities.

  15. Control the horizontal padding of an element to 2.5rem at only small screen sizes using the sm:px-10 utilities.

  16. Set the maximum width/height of an element using the max-w-md utilities.

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

  18. Control the vertical padding of an element to 2rem using the py-8 utilities.

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

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

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

  22. To specify the width between columns, you can use the gap-4 utilities.

  23. Use w-8 to set an element to a fixed width(2rem).

  24. Use h-8 to set an element to a fixed height(2rem).

  25. Control the background color of an element to [#f6cda8] using the bg-[#f6cda8] utilities.

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

  27. Control the background color of an element to [#d89d94] using the bg-[#d89d94] utilities.

  28. Control the background color of an element to [#dd6b6c] using the bg-[#dd6b6c] utilities.

  29. Control the background color of an element to [#875d71] using the bg-[#875d71] utilities.

  30. Control the background color of an element to [#5b5b5b] using the bg-[#5b5b5b] utilities.

Conclusion

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