Tailwind CSS 아바타 (Avatar)
아바타(Avatar) 컴포넌트는 웹사이트에서 사용자 프로필의 시각적 식별자로 사용할 수 있어요. Flowbite에서 제공하는 예시를 바탕으로 Tailwind CSS의 유틸리티 클래스를 활용해 스타일과 크기를 자유롭게 조절할 수 있습니다.
출처: 문서
본문
기본 아바타 (Default avatar)
이미지 요소에 원형(circle)과 둥근(rounded) 아바타를 만드는 기본 예시예요. rounded-full은 완전한 원형, rounded-base는 부드럽게 둥근 모서리를 만듭니다.
<img class="w-10 h-10 rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="Rounded avatar">
<img class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="Default avatar">
테두리 아바타 (Bordered avatar)
ring 유틸리티를 사용해 이미지 주위에 테두리 링을 추가할 수 있어요. ring-2와 ring-default 색상을 조합해 깔끔한 테두리를 만들 수 있습니다.
<img class="w-10 h-10 p-1 rounded-full ring-2 ring-default" src="/docs/images/people/profile-picture-5.jpg" alt="Bordered avatar">
아이콘 아바타 (Avatar with icon)
이미지 대신 SVG 아이콘을 아바타로 사용할 수도 있어요. bg-neutral-secondary-medium 배경 위에 사용자 아이콘을 배치합니다.
<div class="relative w-10 h-10 overflow-hidden bg-neutral-secondary-medium rounded-full">
<svg class="absolute w-12 h-12 text-body-subtle -left-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg>
</div>
이니셜 아바타 (Avatar with initials)
이미지 대신 사용자의 이름 이니셜을 표시할 수 있어요. 배경색을 바꾸고 span 요소에 이니셜 텍스트를 넣으면 됩니다.
<div class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-neutral-tertiary rounded-full">
<span class="font-medium text-body">JL</span>
</div>
툴팁이 있는 아바타 (Avatar with tooltip)
아바타에 마우스를 올리면 이름이 표시되는 툴팁을 추가할 수 있어요. Flowbite의 tooltip 컴포넌트를 조합해 사용합니다.
<div>
<div id="tooltip-jese" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-dark rounded-base shadow-xs opacity-0 tooltip">
Jese Leos
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<img data-tooltip-target="tooltip-jese" class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="Medium avatar">
</div>
<div>
<div id="tooltip-roberta" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-dark rounded-base shadow-xs opacity-0 tooltip">
Roberta Casas
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<img data-tooltip-target="tooltip-roberta" class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-4.jpg" alt="Medium avatar">
</div>
<div>
<div id="tooltip-bonnie" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-dark rounded-base shadow-xs opacity-0 tooltip">
Bonnie Green
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<img data-tooltip-target="tooltip-bonnie" class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-3.jpg" alt="Medium avatar">
</div>
상태 표시 아바타 (Avatar with dot indicator)
아바타 모서리에 온라인/오프라인 상태를 나타내는 작은 점(dot)을 추가할 수 있어요. bg-success는 온라인, bg-danger는 오프라인을 의미합니다.
<div class="relative">
<img class="w-10 h-10 rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="">
<span class="top-0 left-7 absolute w-3.5 h-3.5 bg-success border-2 border-buffer rounded-full"></span>
</div>
<div class="relative">
<img class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="">
<span class="absolute top-0 left-8 transform -translate-y-1/2 w-3.5 h-3.5 bg-danger border-2 border-buffer rounded-full"></span>
</div>
<div class="relative">
<img class="w-10 h-10 rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="">
<span class="bottom-0 left-7 absolute w-3.5 h-3.5 bg-success border-2 border-buffer rounded-full"></span>
</div>
<div class="relative">
<img class="w-10 h-10 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="">
<span class="absolute bottom-0 left-8 transform translate-y-1/4 w-3.5 h-3.5 bg-success border-2 border-buffer rounded-full"></span>
</div>
겹친 아바타 (Stacked avatar)
여러 아바타를 겹쳐서 표시하는 그룹 아바타를 만들 수 있어요. -space-x-4로 간격을 겹치게 하고, 마지막에 +99 같은 추가 인원 수를 표시할 수 있습니다.
<div class="flex -space-x-4 rtl:space-x-reverse">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-2.jpg" alt="">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-3.jpg" alt="">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-4.jpg" alt="">
</div>
<div class="flex -space-x-4 rtl:space-x-reverse">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-2.jpg" alt="">
<img class="w-10 h-10 border-2 border-buffer rounded-full" src="/docs/images/people/profile-picture-3.jpg" alt="">
<a class="flex items-center justify-center w-10 h-10 text-xs font-medium text-white bg-dark-strong border-2 border-buffer rounded-full" href="#">+99</a>
</div>
텍스트가 포함된 아바타 (Avatar with text)
아바타 옆에 사용자 이름과 가입일 같은 텍스트 정보를 함께 표시할 수 있어요.
<div class="flex items-center gap-2.5">
<img class="w-10 h-10 rounded-full" src="/docs/images/people/profile-picture-5.jpg" alt="">
<div class="font-medium text-heading">
<div>Jese Leos</div>
<div class="text-sm font-normal text-body">Joined in August 2014</div>
</div>
</div>
사용자 드롭다운 (User dropdown)
아바타를 클릭하면 사용자 메뉴가 열리는 드롭다운 형태로 활용할 수 있어요. data-dropdown-toggle 속성으로 드롭다운과 연결합니다.
<img id="avatarButton" type="button" data-dropdown-toggle="userDropdown" data-dropdown-placement="bottom-start" class="w-10 h-10 rounded-full cursor-pointer" src="/docs/images/people/profile-picture-5.jpg" alt="User dropdown">
<!-- Dropdown menu -->
<div id="userDropdown" class="z-10 hidden bg-neutral-primary-medium border border-default-medium rounded-base shadow-lg w-44">
<div class="px-4 py-3 border-b border-default-medium text-sm text-heading">
<div class="font-medium">Bonnie Green</div>
<div class="truncate">name@flowbite.com</div>
</div>
<ul class="p-2 text-sm text-body font-medium" aria-labelledby="avatarButton">
<li>
<a href="#" class="block w-full p-2 hover:bg-neutral-tertiary-medium hover:text-heading rounded-md">Dashboard</a>
</li>
<li>
<a href="#" class="block w-full p-2 hover:bg-neutral-tertiary-medium hover:text-heading rounded-md">Settings</a>
</li>
<li>
<a href="#" class="block w-full p-2 hover:bg-neutral-tertiary-medium hover:text-heading rounded-md">Earnings</a>
</li>
<li>
<a href="#" class="block w-full p-2 hover:bg-neutral-tertiary-medium text-fg-danger rounded-md">Sign out</a>
</li>
</ul>
</div>
아바타 크기 (Avatar sizes)
w-*와 h-* 유틸리티 클래스를 바꿔 아바타 크기를 조절할 수 있어요. 아주 작은(extra small) 크기부터 2xl 크기까지 다양하게 제공됩니다.
<img class="w-4.5 h-4.5 rounded-sm" src="/docs/images/people/profile-picture-5.jpg" alt="Extra small avatar">
<img class="w-6 h-6 rounded-sm" src="/docs/images/people/profile-picture-5.jpg" alt="Small avatar">
<img class="w-8 h-8 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="Base avatar">
<img class="w-11 h-11 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="Large avatar">
<img class="w-14 h-14 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="xl avatar">
<img class="w-16 h-16 rounded-base" src="/docs/images/people/profile-picture-5.jpg" alt="2xl avatar">