Published on

Learn How To Make A Simple Avatar (and initials) With Tailwind CSS Like an Expert

Tags
Simple Avatar (and initials)

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 Simple Avatar (and initials) ui component

Simple avatar with initials avatar on hover state can be used anywhere.

Why use Tailwind CSS to make a Simple Avatar (and initials) ui component?

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

The preview of Simple Avatar (and initials) ui component

Free download of the Simple Avatar (and initials)'s source code

The source code of Simple Avatar (and initials) ui component

<section>
  <h1 class="w-full">Avatar Component with initials (on hover)</h1>
  <div class="w-10 h-10 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-12 h-12 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-16 h-16 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-24 h-24 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-32 h-32 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-48 h-48 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
  
  <div class="w-64 h-64 relative mb-4">
    <div class="group w-full h-full rounded-full overflow-hidden shadow-inner text-center bg-purple table cursor-pointer">
      <span class="hidden group-hover:table-cell text-white font-bold align-middle">KR</span>
      <img src="https://pickaface.net/gallery/avatar/unr_random_180410_1905_z1exb.png" alt="lovely avatar" class="object-cover object-center w-full h-full visible group-hover:hidden" />
    </div>
  </div>
</section>

How to make a Simple Avatar (and initials) with Tailwind CSS?

Install tailwind css of verion 0.3.0

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

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

All the unility class needed to make a Simple Avatar (and initials) component

  • w-full
  • w-10
  • h-10
  • relative
  • mb-4
  • h-full
  • overflow-hidden
  • text-center
  • bg-purple
  • table
  • hidden
  • group-hover:table-cell
  • text-white
  • visible
  • group-hover:hidden
  • w-12
  • h-12
  • w-16
  • h-16
  • w-24
  • h-24
  • w-32
  • h-32
  • w-48
  • h-48
  • w-64
  • h-64

27 steps to make a Simple Avatar (and initials) component with Tailwind CSS

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

  2. Use w-10 to set an element to a fixed width(2.5rem).

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

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

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

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

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

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

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

  10. Use the table utilities to create elements that behave like their respective table elements.

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

  12. Use the table utilities to create elements that behave like their respective table elementsundefined.

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

  14. Use visible to make an element visible. This is mostly useful for undoing the invisible utility at different screen sizes.

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

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

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

  18. Use w-16 to set an element to a fixed width(4rem).

  19. Use h-16 to set an element to a fixed height(4rem).

  20. Use w-24 to set an element to a fixed width(6rem).

  21. Use h-24 to set an element to a fixed height(6rem).

  22. Use w-32 to set an element to a fixed width(8rem).

  23. Use h-32 to set an element to a fixed height(8rem).

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

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

  26. Use w-64 to set an element to a fixed width(16rem).

  27. Use h-64 to set an element to a fixed height(16rem).

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to make a Simple Avatar (and initials) components, learn and follow along to implement your own components.