Skip to content

CSS: avatar

.instui-avatar · stable — รูปโปรไฟล์ผู้ใช้ที่แสดงตัวอักษรย่อหรือรูปภาพ โดยเป็นรูปทรงกลมเป็นค่าเริ่มต้น.

โดยค่าเริ่มต้น พาเล็ตต์สีจะย้อมตัวอักษรย่อบนพื้นผิวโปร่งใส; -has-inverse-color จะเติมพื้นผิวด้วยสีและวางตัวอักษรย่อบนพื้นสีนั้น. ชนิด -color-ai จะเติมเสมอด้วยไล่สี violet→sea. หากต้องการแสดงชื่อเต็ม ให้ใส่ในเนื้อหา (เพื่อให้คงอยู่ใน tree ของการช่วยเข้าถึง) และเพิ่ม data-initials="XX" สำหรับหน้าตาแบบกะทัดรัด — ข้อความจริงคือสิ่งที่โปรแกรมอ่านหน้าจอประกาศ. หากไม่มี data-initials เนื้อหาที่ล้นจะถูกตัดแบบแข็ง (ไม่มีเครื่องหมายสามจุด); ห่อด้วย .name เพื่อการตัดที่แน่นอนซึ่งเก็บเพียงตัวอักษรต้นเดียว หรือแยกเป็น .first-name/.last-name สำหรับตัวอักษรสองตัวที่ถูกตัด (สามารถละครึ่งใดครึ่งหนึ่งได้และอีกส่วนจะยังคงอยู่กึ่งกลาง).

Source: avatar.css

TIP

การปรับปรุง JS — CSS ของคอมโพเนนต์นี้เรนเดอร์และทำงานได้ด้วยตัวเอง; จับคู่กับ @pantoken/interactions เพื่อเพิ่มพฤติกรรมเชิงโต้ตอบ ดู ตารางตัวปรับแต่งด้านล่าง.

การเข้าถึง

ให้รูปโปรไฟล์ที่เป็นภาพมี alt ที่มีความหมาย (ชื่อบุคคล) ไม่ใช่คำว่า "avatar" ทั่วไป; สำหรับอวาตาร์ที่มีเพียงตัวอักษรย่อ ให้ใช้เนื้อหาชื่อจริง (ข้อความเปล่า, data-initials, .name หรือ .first-name/.last-name) แทนตัวอักษรย่อที่เตรียมไว้ล่วงหน้า เพื่อให้เทคโนโลยีช่วยเหลือประกาศชื่อจริง.

การใช้งาน

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/avatar.css";

ตัวอย่าง

html
<span class="instui-avatar --me-sm">LH</span>
<span class="instui-avatar -color-ai --me-sm">AI</span>
<span class="instui-avatar --me-sm" data-initials="NV">Dr. Nguyen Van Thoc</span>
<span class="instui-avatar"><span class="name">Miguel Sanchez</span></span>
<span class="instui-avatar"><span class="first-name">Miguel</span> <span class="last-name">Sanchez</span></span>

โครงสร้าง

อวาตาร์จะแสดงหนึ่งใน: <img>, ข้อความเปล่า/ข้อมูล-initials, ห่อด้วย .name, หรือคู่ .first-name/.last-name.

text
.instui-avatar
  img (0..1)
  .name (0..1)
  .first-name (0..1)
  .last-name (0..1)
flowchart TD n0[".instui-avatar"]:::cssdoc-root n1("img"):::cssdoc-part n2(".name"):::cssdoc-part n3(".first-name"):::cssdoc-part n4(".last-name"):::cssdoc-part n0 -.->|0..1| n1 n0 -.->|0..1| n2 n0 -.->|0..1| n3 n0 -.->|0..1| n4 classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

ตัวปรับแต่ง

ตัวปรับแต่งคำอธิบาย
.-color-accent1เลิกใช้ — use .-color-blue.
.-color-accent2เลิกใช้ — use .-color-green.
.-color-accent3เลิกใช้ — use .-color-red.
.-color-accent4เลิกใช้ — use .-color-orange.
.-color-accent5เลิกใช้ — use .-color-ash.
.-color-accent6เลิกใช้ — use .-color-grey.
.-color-aiสีพาเล็ตต์เน้น AI.
.-color-ashสีพาเล็ตต์ Ash.
.-color-blueสีพาเล็ตต์ Blue.
.-color-greenสีพาเล็ตต์ Green.
.-color-greyสีพาเล็ตต์ Grey.
.-color-orangeสีพาเล็ตต์ Orange.
.-color-redสีพาเล็ตต์ Red.
.-has-inverse-colorใช้สีข้อความแบบผกผัน (บนพื้นมืด).
.-shape-rectangleรูปทรงสี่เหลี่ยม (สี่เหลี่ยมผืนผ้า) แทนวงกลม.
.-show-borderAlias — maps to .-show-border-always.
.-show-border-alwaysบังคับให้แหวนขอบปรากฏ แม้บนภาพหรือการเติมแบบผกผัน.
.-show-border-neverบังคับให้แหวนขอบปิด.
.-size-2xlขนาดใหญ่ขึ้นสองระดับ.
.-size-2xsขนาดเล็กลงสองระดับ.
.-size-largeใหญ่. ชื่อยาวของ -size-lg.
.-size-lgใหญ่.
.-size-mdกลาง (ค่าเริ่มต้น).
.-size-mediumกลาง (ค่าเริ่มต้น). ชื่อยาวของ -size-md.
.-size-smเล็ก.
.-size-smallเล็ก. ชื่อยาวของ -size-sm.
.-size-x-largeใหญ่พิเศษ. ชื่อยาวของ -size-xl.
.-size-x-smallเล็กพิเศษ. ชื่อยาวของ -size-xs.
.-size-xlใหญ่พิเศษ.
.-size-xsเล็กพิเศษ.
.-size-xx-largeขนาดใหญ่ขึ้นสองระดับ. ชื่อยาวของ -size-2xl.
.-size-xx-smallขนาดเล็กลงสองระดับ. ชื่อยาวของ -size-2xs.

ส่วนประกอบ

ส่วนคำอธิบาย
.first-nameไม่บังคับ (จับคู่กับ .last-name): ห่อชื่อที่ให้มา ตัดให้เหลือเพียงตัวอักษรหน้า.
.last-nameไม่บังคับ (จับคู่กับ .first-name): ห่อชื่อสกุล ตัดให้เหลือเพียงตัวอักษรหน้า.
.nameOptional: wrap the full name to clip it to a single leading letter without data-initials or JS.

องค์ประกอบเทียม

องค์ประกอบเทียมคำอธิบาย
::before

โทเค็นที่ใช้

Tokenชนิดค่า
--instui-component-avatar-ai-bottom-gradient-color<color>#00828E
--instui-component-avatar-ai-top-gradient-color<color>#9E58BD
--instui-component-avatar-ash-background-color<color>LightDarklight-dark(#273540, #1C222B)
--instui-component-avatar-ash-text-color<color>LightDarklight-dark(#273540, #C7CACD)
--instui-component-avatar-background-color<color>LightDarklight-dark(#ffffff, #10141A)
--instui-component-avatar-blue-background-color<color>#2B7ABC
--instui-component-avatar-blue-text-color<color>LightDarklight-dark(#2871AF, #7FB4F1)
--instui-component-avatar-border-color<color>LightDarklight-dark(#8D959F, #6A7883)
--instui-component-avatar-border-width-md<length>0.125rem
--instui-component-avatar-border-width-sm<length>0.0625rem
--instui-component-avatar-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-avatar-font-size-lg<length>1.25rem
--instui-component-avatar-font-size-md<length>1rem
--instui-component-avatar-font-size-sm<length>0.875rem
--instui-component-avatar-font-size-xl<length>1.75rem
--instui-component-avatar-font-size-xs<length>0.75rem
--instui-component-avatar-font-size2xl<length>2.5rem
--instui-component-avatar-font-size2xs<length>0.75rem
--instui-component-avatar-font-weight<integer>600
--instui-component-avatar-green-background-color<color>#03893D
--instui-component-avatar-green-text-color<color>LightDarklight-dark(#037D37, #61C378)
--instui-component-avatar-grey-background-color<color>LightDarklight-dark(#4A5B68, #576773)
--instui-component-avatar-grey-text-color<color>LightDarklight-dark(#4A5B68, #F2F4F5)
--instui-component-avatar-orange-background-color<color>#CF4A00
--instui-component-avatar-orange-text-color<color>LightDarklight-dark(#BB4200, #FF905A)
--instui-component-avatar-rectangle-radius<length>0.25rem
--instui-component-avatar-red-background-color<color>#E62429
--instui-component-avatar-red-text-color<color>LightDarklight-dark(#CF1F24, #FA917F)
--instui-component-avatar-size-lg<length>3.5rem
--instui-component-avatar-size-md<length>3rem
--instui-component-avatar-size-sm<length>2.5rem
--instui-component-avatar-size-xl<length>4rem
--instui-component-avatar-size-xs<length>2rem
--instui-component-avatar-size2xl<length>5rem
--instui-component-avatar-size2xs<length>1.5rem
--instui-component-avatar-text-on-color<color>#ffffff

ที่เกี่ยวข้อง

  • byline — สามารถโฮสต์อวาตาร์เป็นภาพนำ (leading hero) ได้.