尺寸
用于设置元素宽度的实用工具。
类名 | 样式 |
---|---|
w-<number> | width: calc(var(--spacing) * <number>); |
w-<fraction> | width: calc(<fraction> * 100%); |
w-3xs | width: var(--container-3xs); /* 16rem (256px) */ |
w-2xs | width: var(--container-2xs); /* 18rem (288px) */ |
w-xs | width: var(--container-xs); /* 20rem (320px) */ |
w-sm | width: var(--container-sm); /* 24rem (384px) */ |
w-md | width: var(--container-md); /* 28rem (448px) */ |
w-lg | width: var(--container-lg); /* 32rem (512px) */ |
w-xl | width: var(--container-xl); /* 36rem (576px) */ |
w-2xl | width: var(--container-2xl); /* 42rem (672px) */ |
w-3xl | width: var(--container-3xl); /* 48rem (768px) */ |
w-4xl | width: var(--container-4xl); /* 56rem (896px) */ |
w-5xl | width: var(--container-5xl); /* 64rem (1024px) */ |
w-6xl | width: var(--container-6xl); /* 72rem (1152px) */ |
w-7xl | width: var(--container-7xl); /* 80rem (1280px) */ |
w-auto | width: auto; |
w-px | width: 1px; |
w-full | width: 100%; |
w-screen | width: 100vw; |
w-dvw | width: 100dvw; |
w-dvh | width: 100dvh; |
w-lvw | width: 100lvw; |
w-lvh | width: 100lvh; |
w-svw | width: 100svw; |
w-svh | width: 100svh; |
w-min | width: min-content; |
w-max | width: max-content; |
w-fit | width: fit-content; |
w-(<custom-property>) | width: var(<custom-property>); |
w-[<value>] | width: <value>; |
size-<number> | width: calc(var(--spacing) * <number>); height: calc(var(--spacing) * <number>); |
size-<fraction> | width: calc(<fraction> * 100%); height: calc(<fraction> * 100%); |
size-auto | width: auto; height: auto; |
size-px | width: 1px; height: 1px; |
size-full | width: 100%; height: 100%; |
size-dvw | width: 100dvw; height: 100dvw; |
size-dvh | width: 100dvh; height: 100dvh; |
size-lvw | width: 100lvw; height: 100lvw; |
size-lvh | width: 100lvh; height: 100lvh; |
size-svw | width: 100svw; height: 100svw; |
size-svh | width: 100svh; height: 100svh; |
size-min | width: min-content; height: min-content; |
size-max | width: max-content; height: max-content; |
size-fit | width: fit-content; height: fit-content; |
size-(<custom-property>) | width: var(<custom-property>); height: var(<custom-property>); |
size-[<value>] | width: <value>; height: <value>; |
使用 w-<number>
实用工具,例如 w-24
和 w-64
,以根据间距比例设置元素的固定宽度
<div class="w-96 ...">w-96</div><div class="w-80 ...">w-80</div><div class="w-64 ...">w-64</div><div class="w-48 ...">w-48</div><div class="w-40 ...">w-40</div><div class="w-32 ...">w-32</div><div class="w-24 ...">w-24</div>
使用 w-full
或 w-<fraction>
实用工具,例如 w-1/2
和 w-2/5
,为元素提供基于百分比的宽度
<div class="flex ..."> <div class="w-1/2 ...">w-1/2</div> <div class="w-1/2 ...">w-1/2</div></div><div class="flex ..."> <div class="w-2/5 ...">w-2/5</div> <div class="w-3/5 ...">w-3/5</div></div><div class="flex ..."> <div class="w-1/3 ...">w-1/3</div> <div class="w-2/3 ...">w-2/3</div></div><div class="flex ..."> <div class="w-1/4 ...">w-1/4</div> <div class="w-3/4 ...">w-3/4</div></div><div class="flex ..."> <div class="w-1/5 ...">w-1/5</div> <div class="w-4/5 ...">w-4/5</div></div><div class="flex ..."> <div class="w-1/6 ...">w-1/6</div> <div class="w-5/6 ...">w-5/6</div></div><div class="w-full ...">w-full</div>
使用 w-sm
和 w-xl
等实用工具,以根据容器比例设置元素的固定宽度
<div class="w-xl ...">w-xl</div><div class="w-lg ...">w-lg</div><div class="w-md ...">w-md</div><div class="w-sm ...">w-sm</div><div class="w-xs ...">w-xs</div><div class="w-2xs ...">w-2xs</div><div class="w-3xs ...">w-3xs</div>
使用 w-screen
实用工具使元素跨越整个视口的宽度
<div class="w-screen"> <!-- ... --></div>
或者,您可以使用 w-lvw
、w-svw
和 w-dvw
实用工具来匹配大型、小型或动态视口的宽度。
使用 w-auto
实用工具在特定条件下(例如在特定断点处)移除元素指定的宽度
<div class="w-full md:w-auto"> <!-- ... --></div>
使用 size-px
、size-4
和 size-full
等实用工具,同时设置元素的宽度和高度
<div class="size-16 ...">size-16</div><div class="size-20 ...">size-20</div><div class="size-24 ...">size-24</div><div class="size-32 ...">size-32</div><div class="size-40 ...">size-40</div>
使用 w-[<value>]
语法 来设置宽度基于完全自定义的值
<div class="w-[5px] ..."> <!-- ... --></div>
对于 CSS 变量,您还可以使用 w-(<custom-property>)
语法
<div class="w-(--my-width) ..."> <!-- ... --></div>
这只是 w-[var(<custom-property>)]
的简写形式,它会自动为您添加 var()
函数。
前缀将 width
实用工具 与断点变体(如 md:
)一起使用,以仅在medium 屏幕尺寸及以上应用该实用工具
<div class="w-1/2 md:w-full ..."> <!-- ... --></div>
了解更多关于在 变体文档 中使用变体的信息。
的 w-<number>
和 size-<number>
实用工具由 --spacing
主题变量驱动,该变量可以在您自己的主题中自定义
@theme { --spacing: 1px; }
了解更多关于在 主题变量文档 中自定义间距比例的信息。