Published on

The 5 Really Obvious Ways To Make A Card Product With Tailwind CSS Better That You Ever Did

Tags
Card product

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

Tailwind css v 2.x recommandation

Why use Tailwind CSS to create a Card product ui component?

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

The preview of Card product ui component

Free download of the Card product's source code

The source code of Card product ui component

<div class="flex flex-col gap-6 items-center h-screen w-full bg-gray-50 flex items-center justify-center">
  <div class="w-3/2 bg-gray-200 overflow-hidden rounded-xl">
    <div class="flex">
      <div class="flex-none w-48 relative">
        <img src="http://lorempixel.com/500/500/sports/1/Dummy-Text/" alt="" class="absolute inset-0 w-full h-full object-cover" />
      </div>
      <form class="flex-auto p-6">
        <div class="flex flex-wrap">
          <h1 class="text-blue font-bold flex-auto text-xl font-semibold">
            Classic Utility Jacket
          </h1>
          
          <div class="text-xl font-semibold text-gray-500">
            $326.00
          </div>
          <div class="w-full flex-none text-sm font-medium text-gray-500 mt-2">
            In stock
          </div>
        </div>
        <p class="mt-4 text-sm text-gray-500">
          Free shipping on all continental US orders.
        </p>
        <div class="flex items-baseline mt-4 mb-6">
          <div class="space-x-2 flex">
            <label class="w-8 h-8 rounded shadow-sm text-center flex items-center justify-center bg-white">
              <input class="hidden focus-within:w-6 h-6 flex items-center justify-center bg-gray-100 rounded-lg" name="size" type="radio" value="xs" checked>
              XS
            </label>
            <label class="w-8 h-8 rounded shadow-sm text-center flex items-center justify-center bg-white">
              <input class="hidden focus-within:w-6 h-6 flex items-center justify-center bg-gray-100 rounded-lg" name="size" type="radio" value="xs" checked>
              S
            </label>
            <label class="w-8 h-8 rounded shadow-sm text-center flex items-center justify-center bg-white">
              <input class="hidden focus-within:w-6 h-6 flex items-center justify-center bg-gray-100 rounded-lg" name="size" type="radio" value="xs" checked>
              M
            </label>
            <label class="w-8 h-8 rounded shadow-sm text-center flex items-center justify-center bg-white">
              <input class="hidden focus-within:w-6 h-6 flex items-center justify-center bg-gray-100 rounded-lg" name="size" type="radio" value="xs" checked>
              L
            </label>
            <label class="w-8 h-8 rounded shadow-sm text-center flex items-center justify-center bg-white">
              <input class="hidden focus-within:w-6 h-6 flex items-center justify-center bg-gray-100 rounded-lg" name="size" type="radio" value="xs" checked>
              XL
            </label>
          </div>
          <div class="ml-auto text-xs text-gray-500 underline">Voir plus</div>
        </div>
        <div class="flex space-x-3 mb-4 text-sm font-medium">
          <div class="flex-auto flex space-x-3">
            <button class="uppercase text-xs font-bold w-1/2 flex items-center justify-center rounded-full bg-blue-400 text-white" type="submit">
            Acheter</button>
            <button class="uppercase text-xs font-bold w-1/2 flex items-center justify-center rounded-full border border-gray-300" type="button">Ajouter</button>
          </div>
          <button class="flex-none flex items-center justify-center w-9 h-9 rounded-md text-gray-400 border border-red-300 hover:animate-ping" type="button" aria-label="like">
            <svg width="20" height="20" fill="currentColor" class="fill-current text-red-300">
              <path fill-rule="evenodd" clip-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" />
            </svg>
          </button>
        </div>
        
      </form>
    </div>
  </div>

  <div class="max-w-screen-sm bg-purple-800 overflow-hidden rounded-xl">
    <div class="flex">
      <div class="flex-none w-48 relative">
        <img src="http://lorempixel.com/output/fashion-h-c-301-499-7.jpg" alt="" class="absolute inset-0 w-full h-full object-cover" />
      </div>
      <form class="flex-auto p-6">
        <div class="flex flex-wrap">
          <h1 class="text-white font-bold flex-auto text-xl font-semibold">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit.
          </h1>
        
          <div class="w-full flex-none text-sm font-bold text-green-300 mt-2 text-xl">
            300 000 <sup class="font-light text-xs">Ar</sup>
          </div>
        </div>
        <p class="mt-4 text-sm text-gray-200">
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet aperiam architecto aspernatur eveniet in mollitia nisi nulla rerum vel. Expedita?
        </p>
        <div class="flex items-baseline mt-4 mb-6">
          <div class="space-x-2 flex">
            <label class="w-8 h-8 rounded-full shadow-sm bg-gradient-to-r from-purple-900 to-purple-700 shadow-md text-center-2 flex items-center justify-center bg-none bg-purple-700">
              <svg height="20" width="20" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current text-purple-300">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.618 5.984A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016zM12 9v2m0 4h.01" />
              </svg>
            </label>
            <label class="w-8 h-8 rounded-full shadow-sm bg-gradient-to-r from-purple-900 to-purple-700 shadow-md text-center-2 flex items-center justify-center bg-none bg-purple-700">
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" height="20" width="20" class="strocke-current text-purple-300">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
              </svg>
            </label>
            <label class="w-8 h-8 rounded-full shadow-sm bg-gradient-to-r from-purple-900 to-purple-700 shadow-md text-center-2 flex items-center justify-center bg-none bg-purple-700">
              <svg height="20" width="20" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current text-purple-300">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.618 5.984A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016zM12 9v2m0 4h.01" />
              </svg>
            </label>
            <label class="w-8 h-8 rounded-full shadow-sm bg-gradient-to-r from-purple-900 to-purple-700 shadow-md text-center-2 flex items-center justify-center bg-none bg-purple-700">
              <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" height="20" width="20" class="strocke-current text-purple-300">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
              </svg>
            </label>
          </div>
          <div class="ml-auto text-xs text-gray-500 underline">Voir plus</div>
        </div>
        <div class="flex space-x-3 mb-4 text-sm font-medium">
          <div class="flex-auto flex space-x-3">
            <button class="uppercase text-xs text-gray-800 font-bold w-1/2 flex items-center justify-center rounded-full bg-green-400 text-white" type="submit">
            Acheter</button></div>
          <button class="flex-none flex items-center justify-center w-9 h-9 rounded-md text-gray-400 border border-red-300 hover:animate-ping" type="button" aria-label="like">
            <svg width="20" height="20" fill="currentColor" class="fill-current text-red-300">
              <path fill-rule="evenodd" clip-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" />
            </svg>
          </button>
        </div>
        
      </form>
    </div>
  </div>
</div>

How to create a Card product with Tailwind CSS?

Install tailwind css of verion 1.9.6

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

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

All the unility class needed to create a Card product component

  • flex
  • flex-col
  • gap-6
  • h-screen
  • w-full
  • bg-gray-50
  • w-3/2
  • bg-gray-200
  • overflow-hidden
  • flex-none
  • w-48
  • relative
  • absolute
  • h-full
  • flex-auto
  • p-6
  • flex-wrap
  • text-blue
  • text-xl
  • text-gray-500
  • text-sm
  • mt-2
  • mt-4
  • mb-6
  • w-8
  • h-8
  • text-center
  • bg-white
  • hidden
  • focus-within:w-6
  • h-6
  • bg-gray-100
  • ml-auto
  • text-xs
  • mb-4
  • w-1/2
  • bg-blue-400
  • text-white
  • border-gray-300
  • w-9
  • h-9
  • text-gray-400
  • border-red-300
  • text-red-300
  • max-w-screen-sm
  • bg-purple-800
  • text-green-300
  • text-gray-200
  • bg-gradient-to-r
  • text-center-2
  • bg-none
  • bg-purple-700
  • text-purple-300
  • text-gray-800
  • bg-green-400

55 steps to create a Card product component with Tailwind CSS

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

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

  3. To specify the width between columns, you can use the gap-6 utilities.

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

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

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

  7. Use w-3/2 to set an element to a fixed width(3/2).

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

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

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

  11. Use w-48 to set an element to a fixed width(12rem).

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

  13. 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.

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

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

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

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

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

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

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

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

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

  23. Control the margin on top side of an element to 1rem using the mt-4 utilities.

  24. Control the margin on bottom side of an element to 1.5rem using the mb-6 utilities.

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

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

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

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

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

  30. Use focus-within:w-6 to set an element to a fixed width(1.5rem)undefined.

  31. Use h-6 to set an element to a fixed height(1.5rem).

  32. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  33. Control the margin on left side of an element to auto using the ml-auto utilities.

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

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

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

  37. Control the background color of an element to blue-400 using the bg-blue-400 utilities.

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

  39. Control the border color of an element to gray-300 using the border-gray-300 utilities.

  40. Use w-9 to set an element to a fixed width(2.25rem).

  41. Use h-9 to set an element to a fixed height(2.25rem).

  42. Control the text color of an element to gray-400 using the text-gray-400 utilities.

  43. Control the border color of an element to red-300 using the border-red-300 utilities.

  44. Control the text color of an element to red-300 using the text-red-300 utilities.

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

  46. Control the background color of an element to purple-800 using the bg-purple-800 utilities.

  47. Control the text color of an element to green-300 using the text-green-300 utilities.

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

  49. Control the background color of an element to gradient-to-r using the bg-gradient-to-r utilities.

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

  51. Control the background color of an element to none using the bg-none utilities.

  52. Control the background color of an element to purple-700 using the bg-purple-700 utilities.

  53. Control the text color of an element to purple-300 using the text-purple-300 utilities.

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

  55. Control the background color of an element to green-400 using the bg-green-400 utilities.

Conclusion

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