1. 尺寸
  2. min-width

尺寸

min-width

用于设置元素最小宽度的工具。

样式
min-w-<number>
min-width: calc(var(--spacing) * <number>);
min-w-<fraction>
min-width: calc(<fraction> * 100%);
min-w-3xs
min-width: var(--container-3xs); /* 16rem (256px) */
min-w-2xs
min-width: var(--container-2xs); /* 18rem (288px) */
min-w-xs
min-width: var(--container-xs); /* 20rem (320px) */
min-w-sm
min-width: var(--container-sm); /* 24rem (384px) */
min-w-md
min-width: var(--container-md); /* 28rem (448px) */
min-w-lg
min-width: var(--container-lg); /* 32rem (512px) */
min-w-xl
min-width: var(--container-xl); /* 36rem (576px) */
min-w-2xl
min-width: var(--container-2xl); /* 42rem (672px) */

示例(Examples)

¥Examples

基本示例(Basic example)

¥Basic example

使用 min-w-<number> 工具(如 min-w-24min-w-64)根据间距比例将元素设置为固定的最小宽度:

¥Use min-w-<number> utilities like min-w-24 and min-w-64 to set an element to a fixed minimum width based on the spacing scale:

min-w-80
min-w-64
min-w-48
min-w-40
min-w-32
min-w-24
<div class="w-20 ...">
<div class="min-w-80 ...">min-w-80</div>
<div class="min-w-64 ...">min-w-64</div>
<div class="min-w-48 ...">min-w-48</div>
<div class="min-w-40 ...">min-w-40</div>
<div class="min-w-32 ...">min-w-32</div>
<div class="min-w-24 ...">min-w-24</div>
</div>

使用百分比(Using a percentage)

¥Using a percentage

使用 min-w-fullmin-w-<fraction> 工具(如 min-w-1/2min-w-2/5)为元素提供基于百分比的最小宽度:

¥Use min-w-full or min-w-<fraction> utilities like min-w-1/2 and min-w-2/5 to give an element a percentage-based minimum width:

min-w-1/3
w-full
<div class="flex ...">
<div class="min-w-3/4 ...">min-w-3/4</div>
<div class="w-full ...">w-full</div>
</div>

使用容器比例(Using the container scale)

¥Using the container scale

使用 min-w-smmin-w-xl 等工具根据容器比例将元素设置为固定的最小宽度:

¥Use utilities like min-w-sm and min-w-xl to set an element to a fixed minimum width based on the container scale:

min-w-xs
min-w-2xs
min-w-3xs
<div class="w-40 ...">
<div class="min-w-lg ...">min-w-lg</div>
<div class="min-w-md ...">min-w-md</div>
<div class="min-w-sm ...">min-w-sm</div>
<div class="min-w-xs ...">min-w-xs</div>
<div class="min-w-2xs ...">min-w-2xs</div>
<div class="min-w-3xs ...">min-w-3xs</div>
</div>

使用自定义值(Using a custom value)

¥Using a custom value

使用 min-w-[<value>] 语法 根据完全自定义的值设置 minimum width

<div class="min-w-[220px] ...">
<!-- ... -->
</div>

对于 CSS 变量,还可以使用 min-w-(<custom-property>) 语法:

<div class="min-w-(--my-min-width) ...">
<!-- ... -->
</div>

这只是简写,用于 min-w-[var(<custom-property>)] 它会自动为你添加 var() 函数。

响应式设计(Responsive design)

¥Responsive design

min-width 工具前面使用断点变体如 md: 仅在 medium 屏幕尺寸及以上时应用工具:

<div class="w-24 min-w-full md:min-w-0 ...">
<!-- ... -->
</div>

请参阅 变体文档 详细了解如何使用变体。

自定义主题(Customizing your theme)

¥Customizing your theme

min-w-<number> 工具由 --spacing 主题变量驱动,可以在你自己的主题中进行自定义:

@theme {
--spacing: 1px;
}

主题变量文档中了解有关自定义间距比例的更多信息。

TailwindCSS v4.0 中文网 - 粤ICP备13048890号