1. 尺寸
  2. 最大宽度

Quick reference

Class
Properties
max-w-0max-width: 0px;
max-w-pxmax-width: 1px;
max-w-0.5max-width: 0.125rem; /* 2px */
max-w-1max-width: 0.25rem; /* 4px */
max-w-1.5max-width: 0.375rem; /* 6px */
max-w-2max-width: 0.5rem; /* 8px */
max-w-2.5max-width: 0.625rem; /* 10px */
max-w-3max-width: 0.75rem; /* 12px */
max-w-3.5max-width: 0.875rem; /* 14px */
max-w-4max-width: 1rem; /* 16px */
max-w-5max-width: 1.25rem; /* 20px */
max-w-6max-width: 1.5rem; /* 24px */
max-w-7max-width: 1.75rem; /* 28px */
max-w-8max-width: 2rem; /* 32px */
max-w-9max-width: 2.25rem; /* 36px */
max-w-10max-width: 2.5rem; /* 40px */
max-w-11max-width: 2.75rem; /* 44px */
max-w-12max-width: 3rem; /* 48px */
max-w-14max-width: 3.5rem; /* 56px */
max-w-16max-width: 4rem; /* 64px */
max-w-20max-width: 5rem; /* 80px */
max-w-24max-width: 6rem; /* 96px */
max-w-28max-width: 7rem; /* 112px */
max-w-32max-width: 8rem; /* 128px */
max-w-36max-width: 9rem; /* 144px */
max-w-40max-width: 10rem; /* 160px */
max-w-44max-width: 11rem; /* 176px */
max-w-48max-width: 12rem; /* 192px */
max-w-52max-width: 13rem; /* 208px */
max-w-56max-width: 14rem; /* 224px */
max-w-60max-width: 15rem; /* 240px */
max-w-64max-width: 16rem; /* 256px */
max-w-72max-width: 18rem; /* 288px */
max-w-80max-width: 20rem; /* 320px */
max-w-96max-width: 24rem; /* 384px */
max-w-nonemax-width: none;
max-w-xsmax-width: 20rem; /* 320px */
max-w-smmax-width: 24rem; /* 384px */
max-w-mdmax-width: 28rem; /* 448px */
max-w-lgmax-width: 32rem; /* 512px */
max-w-xlmax-width: 36rem; /* 576px */
max-w-2xlmax-width: 42rem; /* 672px */
max-w-3xlmax-width: 48rem; /* 768px */
max-w-4xlmax-width: 56rem; /* 896px */
max-w-5xlmax-width: 64rem; /* 1024px */
max-w-6xlmax-width: 72rem; /* 1152px */
max-w-7xlmax-width: 80rem; /* 1280px */
max-w-fullmax-width: 100%;
max-w-minmax-width: min-content;
max-w-maxmax-width: max-content;
max-w-fitmax-width: fit-content;
max-w-prosemax-width: 65ch;
max-w-screen-smmax-width: 640px;
max-w-screen-mdmax-width: 768px;
max-w-screen-lgmax-width: 1024px;
max-w-screen-xlmax-width: 1280px;
max-w-screen-2xlmax-width: 1536px;

基本用法

¥Basic usage

设置最大宽度

¥Setting the maximum width

使用 max-w-* 工具设置元素的最大宽度。

¥Set the maximum width of an element using the max-w-* utilities.

max-w-96
max-w-80
max-w-64
max-w-48
max-w-40
max-w-32
max-w-24
<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>

调整大元素的大小

¥Sizing large elements

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.

Andrew Alfred
Assistant to the Traveling Secretary
<div class="max-w-md ...">
  <!-- ... -->
</div>

阅读宽度

¥Reading width

max-w-prose 工具为元素提供了针对可读性优化的最大宽度,并根据字体大小进行调整。

¥The max-w-prose utility gives an element a max-width optimized for readability and adapts based on the font size.

text-sm

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.

text-base

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.

text-xl

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>

限制到你的断点

¥Constraining to your breakpoints

max-w-screen-* 类可用于为元素提供匹配特定断点的最大宽度。这些值自动派生自 tailwind.config.js 文件的 theme.screens section

¥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 lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:max-w-lg to only apply the max-w-lg utility on hover.

<div class="max-w-sm hover:max-w-lg">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:max-w-lg to apply the max-w-lg utility at only medium screen sizes and above.

<div class="max-w-sm md:max-w-lg">
  <!-- ... -->
</div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


使用自定义值

¥Using custom values

自定义主题

¥Customizing your theme

默认情况下,Tailwind 的最大宽度比例是 默认间距比例 以及一些特定于宽度的附加值的组合。

¥By default, Tailwind’s maximum width scale is a combination of the default spacing scale as well as some additional values specific to widths.

你可以通过编辑 tailwind.config.js 文件中的 theme.spacingtheme.extend.spacing 来自定义间距比例。

¥You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '128': '32rem',
      }
    }
  }
}

要单独自定义 max-width,请使用 tailwind.config.js 文件的 theme.maxWidth 部分。

¥To customize max-width separately, use the theme.maxWidth section of your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      maxWidth: {
        '128': '32rem',
      }
    }
  }
}

任意值

¥Arbitrary values

If you need to use a one-off max-width value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

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

Learn more about arbitrary value support in the arbitrary values documentation.