leading-icon-alignment
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLeading Icon Alignment
前置图标对齐
Ensures leading icons within lists are always properly aligned to the first line of text when the text wraps, rather than centering vertically across the full height of the wrapped text.
确保列表中的前置图标在文本换行时始终与文本第一行正确对齐,而非在换行文本的整个高度内垂直居中。
Rules
规则
- MUST: Use on the list item container
flex - MUST: Use height on the SVG that matches the line height of the adjacent text (or
height: 1lhin Tailwind)h-lh - MUST: Use (
flex-shrink: 0in Tailwind) on the icon to prevent it from compressing at narrow widthsshrink-0 - NEVER: Use (
align-items: centerin Tailwind) on the flex container — it vertically centers the icon across all lines of wrapped text instead of aligning to the first lineitems-center
- 必须:在列表项容器上使用布局
flex - 必须:为SVG设置与相邻文本行高匹配的高度(在Tailwind中为
height: 1lh)h-lh - 必须:为图标设置(在Tailwind中为
flex-shrink: 0),防止其在窄宽度下被压缩shrink-0 - 禁止:在flex容器上使用(在Tailwind中为
align-items: center)——这会使图标在所有换行文本行中垂直居中,而非与第一行对齐items-center
Implementation
实现示例
html
<ul>
<li class="flex gap-2">
<svg
class="h-lh w-4 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="10" />
<path d="m9 12 2 2 4-4" />
</svg>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</li>
</ul>html
<ul>
<li class="flex gap-2">
<svg
class="h-lh w-4 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="10" />
<path d="m9 12 2 2 4-4" />
</svg>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</li>
</ul>Key Points
关键点
- The SVG height uses () to match the text line height so the icon visually centers within the first line of text
h-lh - prevents the icon from compressing when the container is narrow — without it the icon distorts before text wraps
shrink-0 - Flex defaults to , but because the SVG has a fixed height, it effectively sits at the top — aligned to the first line
align-items: stretch - provides consistent spacing between icon and text without needing padding or margin on either element
gap-2
- SVG使用设置高度,以匹配文本行高,使图标在视觉上与文本第一行居中对齐
h-lh - 可防止容器变窄时图标被压缩——如果没有这个属性,图标会在文本换行前就发生变形
shrink-0 - Flex布局默认使用,但由于SVG有固定高度,它会自然位于顶部,与第一行文本对齐
align-items: stretch - 在图标和文本之间提供一致的间距,无需为任一元素设置内边距或外边距
gap-2