Max-Width

用于设置页面元素的最大宽度的工具类

Class reference

Class Properties
.max-w-xs max-width: 20rem;
.max-w-sm max-width: 24rem;
.max-w-md max-width: 28rem;
.max-w-lg max-width: 32rem;
.max-w-xl max-width: 36rem;
.max-w-2xl max-width: 42rem;
.max-w-3xl max-width: 48rem;
.max-w-4xl max-width: 56rem;
.max-w-5xl max-width: 64rem;
.max-w-6xl max-width: 72rem;
.max-w-full max-width: 100%;

用法

通过 max-w-{size} 工具类设置页面元素的最大宽度。

max-w-md
<div class="max-w-md mx-auto ...">
  max-w-md
</div>

响应式

如需控制页面元素在特定断点处的最大宽度,请在现有的 max-width 工具类的前面添加 {screen}: 前缀。

进一步了解 Tailwind 的响应式设计功能,请参阅 响应式设计 章节。

Target
Target
Target
Target
Target

定制

Max-Width 比例

tailwind.config.js 配置文件中的 theme.maxWidth 配置段可以定制 Tailwind 的默认 max-width 比例。

// tailwind.config.js
module.exports = {
theme: {
maxWidth: {
+     '1/4': '25%',
+     '1/2': '50%',
+     '3/4': '75%',
}
}
}

前往 定制主题 章节进一步了解定制默认主题的详细信息。

Responsive and pseudo-class variants

By default, only responsive variants are generated for max-width utilities.

You can control which variants are generated for the max-width utilities by modifying the maxWidth property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

// tailwind.config.js
module.exports = {
variants: {
    // ...
-   maxWidth: ['responsive'],
+   maxWidth: ['responsive', 'hover', 'focus'],
}
}

Disabling

If you don't plan to use the max-width utilities in your project, you can disable them entirely by setting the maxWidth property to false in the corePlugins section of your config file:

// tailwind.config.js
module.exports = {
corePlugins: {
    // ...
+   maxWidth: false,
}
}