
尺寸
用于设置元素宽度的工具。
使用 w-px、w-1 和 w-64 等工具将元素设置为固定宽度。
🌐 Use utilities like w-px, w-1, and w-64 to set an element to a fixed width.
<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-1/2 和 w-2/5 等工具将元素设置为百分比宽度。
🌐 Use utilities like w-full, w-1/2, and w-2/5 to set an element to a percentage based width.
<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-screen 使元素占据整个视口的宽度。
🌐 Use w-screen to make an element span the entire width of the viewport.
<div class="w-screen">
<!-- ... -->
</div>
如果你需要在特定条件下移除元素分配的宽度,例如在特定的断点,w-auto 工具会很有用:
🌐 The w-auto utility can be useful if you need to remove an element’s assigned width under a specific condition, like at a particular breakpoint:
<div class="w-full md:w-auto">
<!-- ... -->
</div>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:w-full 仅在 hover 时应用 w-full 工具。
<div class="w-1/2 hover:w-full">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:w-full 仅在中等屏幕尺寸及以上时应用 w-full 工具。
<div class="w-1/2 md:w-full">
<!-- ... -->
</div>
要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 的宽度刻度是默认间距刻度与一些特定于宽度的附加值的组合。
🌐 By default, Tailwind’s width scale is a combination of the default spacing scale as well as some additional values specific to widths.
你可以通过编辑你的 tailwind.config.js 文件中的 theme.spacing 或 theme.extend.spacing 来自定义间距比例。
🌐 You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
要单独自定义宽度,请使用你的 tailwind.config.js 文件中的 theme.width 部分。
🌐 To customize width separately, use the theme.width section of your tailwind.config.js file.
module.exports = {
theme: {
extend: {
width: {
'128': '32rem',
}
}
}
}
在主题自定义文档中了解有关自定义默认主题的更多信息。
🌐 Learn more about customizing the default theme in the theme customization documentation.
如果你需要使用一次性的 width 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<div class="w-[32rem]">
<!-- ... -->
</div>
在 任意值 文档中了解有关任意值支持的更多信息。