
尺寸
用于设置元素最大宽度的工具。
使用 max-w-* 工具设置元素的最大宽度。
🌐 Set the maximum width of an element using the max-w-* utilities.
<div>
<div class="w-full max-w-96 ...">max-w-96</div>
<div class="w-full max-w-80 ...">max-w-80</div>
<div class="w-full max-w-64 ...">max-w-64</div>
<div class="w-full max-w-48 ...">max-w-48</div>
<div class="w-full max-w-40 ...">max-w-40</div>
<div class="w-full max-w-32 ...">max-w-32</div>
<div class="w-full max-w-24 ...">max-w-24</div>
</div>
在 24rem 之上,max-w-* 工具使用命名尺度而不是数字尺度,以使数值更容易猜测。
🌐 Above 24rem, the max-w-* utilities use a named scale instead of a numeric scale to make the values easier to guess.
<div class="max-w-md ...">
<!-- ... -->
</div>
max-w-prose 工具为元素提供经过优化的最大宽度以提高可读性,并会根据字体大小进行适应。
🌐 The max-w-prose utility gives an element a max-width optimized for readability and adapts based on the font size.
Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.
Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.
Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.
<div class="text-sm max-w-prose ...">
<p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.</p>
</div>
<div class="text-base max-w-prose ...">
<p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.</p>
</div>
<div class="text-xl max-w-prose ...">
<p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollar idea right there. Just sell the tops.</p>
</div>
max-w-screen-* 类可以用来给元素设置与特定断点匹配的最大宽度。这些值是自动从你的 tailwind.config.js 文件的 theme.screens 部分 中派生的。
🌐 The max-w-screen-* classes can be used to give an element a max-width matching a specific breakpoint. These values are automatically derived from the theme.screens section of your tailwind.config.js file.
<div class="max-w-screen-2xl">
<!-- ... -->
</div>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:max-w-lg 仅在 hover 时应用 max-w-lg 工具。
<div class="max-w-sm hover:max-w-lg">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:max-w-lg 仅在中等屏幕尺寸及以上时应用 max-w-lg 工具。
<div class="max-w-sm md:max-w-lg">
<!-- ... -->
</div>
要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 的最大宽度刻度是 默认间距刻度 与一组额外的用于 大型元素 的命名尺寸的组合,这些尺寸是 max-w-* 工具独有的。
🌐 By default, Tailwind’s maximum width scale is a combination of the default spacing scale as well as an additional set of named sizes for large elements exclusive to the max-w-* utilities.
你可以通过编辑 tailwind.config.js 文件中的 theme.spacing 或 theme.extend.spacing 来自定义全局间距比例的数值。
🌐 You can customize values in the global spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
要仅为 max-w-* 工具自定义值,请使用 tailwind.config.js 文件中的 theme.maxWidth 部分。
🌐 To customize values for just the max-w-* utilities, use the theme.maxWidth section of your tailwind.config.js file.
module.exports = {
theme: {
extend: {
maxWidth: {
'8xl': '96rem',
}
}
}
}
请注意,在 theme.maxWidth 中定义的值优先于在 theme.spacing 中定义的值,因此向 theme.spacing 添加与默认命名尺寸(如 lg 或 xl)匹配的自定义值不会影响相应的 max-w-* 实用程序。
🌐 Note that values defined in theme.maxWidth take precedence over values defined in theme.spacing, so adding a custom value to theme.spacing that matches one of the default named sizes (like lg or xl) will not affect the corresponding max-w-* utility.
不要在 theme.spacing 下覆盖命名大小
module.exports = {
theme: {
extend: {
spacing: {
'lg': '30rem',
}
}
}
}
使用 theme.maxWidth 来覆盖命名尺寸
module.exports = {
theme: {
extend: {
maxWidth: {
'lg': '30rem',
}
}
}
}
如果你需要使用一次性的 max-width 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<div class="max-w-[220px]">
<!-- ... -->
</div>
在 任意值 文档中了解有关任意值支持的更多信息。