- 入门
- 核心概念
- 定制
- Base Styles
- 布局
- Flexbox & Grid
- Flex Basis
- Flex Direction
- Flex Wrap
- Flex
- Flex Grow
- Flex Shrink
- Order
- Grid Template Columns
- Grid Column Start / End
- Grid Template Rows
- Grid Row Start / End
- Grid Auto Flow
- Grid Auto Columns
- Grid Auto Rows
- Gap
- Justify Content
- Justify Items
- Justify Self
- Align Content
- Align Items
- Align Self
- Place Content
- Place Items
- Place Self
- 间隔
- 尺寸
- 排版
- Font Family
- Font Size
- Font Smoothing
- Font Style
- Font Weight
- Font Variant Numeric
- Letter Spacing
- Line Clamp
- Line Height
- List Style Image
- List Style Position
- List Style Type
- Text Align
- Text Color
- Text Decoration
- Text Decoration Color
- Text Decoration Style
- Text Decoration Thickness
- Text Underline Offset
- Text Transform
- Text Overflow
- Text Wrap
- Text Indent
- Vertical Align
- Whitespace
- Word Break
- Hyphens
- Content
- 背景
- 边框
- Effects
- Filters
- 表格 Tables
- Transitions & Animation
- Transforms
- Interactivity
- SVG
- Accessibility
- 其他
- Install Tailwind CSS using PostCSS
- Framework Guides
- Try Tailwind CSS using the Play CDN
- Install Tailwind CSS with Next.js
- Install Tailwind CSS with Laravel
- Install Tailwind CSS with Vite
- Install Tailwind CSS with Nuxt
- Install Tailwind CSS with Gatsby
- Install Tailwind CSS with SolidJS
- Install Tailwind CSS with SvelteKit
- Install Tailwind CSS with Angular
- Install Tailwind CSS with Ruby on Rails
- Install Tailwind CSS with Remix
- Install Tailwind CSS with Phoenix
- Install Tailwind CSS with Parcel
- Install Tailwind CSS with Symfony
- Install Tailwind CSS with Meteor
- Install Tailwind CSS with Create React App
- Install Tailwind CSS with Adonis
- Install Tailwind CSS With Ember.js
- Install Tailwind CSS with Astro
- Install Tailwind CSS with Qwik
- Install Tailwind CSS with Rspack
Max-Width
Utilities for setting the maximum width of an element.
Quick reference
Class | Properties |
---|---|
max-w-0 | max-width: 0px; |
max-w-px | max-width: 1px; |
max-w-0.5 | max-width: 0.125rem; /* 2px */ |
max-w-1 | max-width: 0.25rem; /* 4px */ |
max-w-1.5 | max-width: 0.375rem; /* 6px */ |
max-w-2 | max-width: 0.5rem; /* 8px */ |
max-w-2.5 | max-width: 0.625rem; /* 10px */ |
max-w-3 | max-width: 0.75rem; /* 12px */ |
max-w-3.5 | max-width: 0.875rem; /* 14px */ |
max-w-4 | max-width: 1rem; /* 16px */ |
max-w-5 | max-width: 1.25rem; /* 20px */ |
max-w-6 | max-width: 1.5rem; /* 24px */ |
max-w-7 | max-width: 1.75rem; /* 28px */ |
max-w-8 | max-width: 2rem; /* 32px */ |
max-w-9 | max-width: 2.25rem; /* 36px */ |
max-w-10 | max-width: 2.5rem; /* 40px */ |
max-w-11 | max-width: 2.75rem; /* 44px */ |
max-w-12 | max-width: 3rem; /* 48px */ |
max-w-14 | max-width: 3.5rem; /* 56px */ |
max-w-16 | max-width: 4rem; /* 64px */ |
max-w-20 | max-width: 5rem; /* 80px */ |
max-w-24 | max-width: 6rem; /* 96px */ |
max-w-28 | max-width: 7rem; /* 112px */ |
max-w-32 | max-width: 8rem; /* 128px */ |
max-w-36 | max-width: 9rem; /* 144px */ |
max-w-40 | max-width: 10rem; /* 160px */ |
max-w-44 | max-width: 11rem; /* 176px */ |
max-w-48 | max-width: 12rem; /* 192px */ |
max-w-52 | max-width: 13rem; /* 208px */ |
max-w-56 | max-width: 14rem; /* 224px */ |
max-w-60 | max-width: 15rem; /* 240px */ |
max-w-64 | max-width: 16rem; /* 256px */ |
max-w-72 | max-width: 18rem; /* 288px */ |
max-w-80 | max-width: 20rem; /* 320px */ |
max-w-96 | max-width: 24rem; /* 384px */ |
max-w-none | max-width: none; |
max-w-xs | max-width: 20rem; /* 320px */ |
max-w-sm | max-width: 24rem; /* 384px */ |
max-w-md | max-width: 28rem; /* 448px */ |
max-w-lg | max-width: 32rem; /* 512px */ |
max-w-xl | max-width: 36rem; /* 576px */ |
max-w-2xl | max-width: 42rem; /* 672px */ |
max-w-3xl | max-width: 48rem; /* 768px */ |
max-w-4xl | max-width: 56rem; /* 896px */ |
max-w-5xl | max-width: 64rem; /* 1024px */ |
max-w-6xl | max-width: 72rem; /* 1152px */ |
max-w-7xl | max-width: 80rem; /* 1280px */ |
max-w-full | max-width: 100%; |
max-w-min | max-width: min-content; |
max-w-max | max-width: max-content; |
max-w-fit | max-width: fit-content; |
max-w-prose | max-width: 65ch; |
max-w-screen-sm | max-width: 640px; |
max-w-screen-md | max-width: 768px; |
max-w-screen-lg | max-width: 1024px; |
max-w-screen-xl | max-width: 1280px; |
max-w-screen-2xl | max-width: 1536px; |
Basic usage
Setting the maximum width
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>
Sizing large elements
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>
Reading width
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.
text-baseOh 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-xlOh 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
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>
Applying conditionally
Hover, focus, and other states
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.
Breakpoints and media queries
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
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.
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',
}
}
}
}
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',
}
}
}
}
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.
Don’t override named sizes under theme.spacing
module.exports = {
theme: {
extend: {
spacing: {
'lg': '30rem',
}
}
}
}
Use theme.maxWidth
to override named sizes
module.exports = {
theme: {
extend: {
maxWidth: {
'lg': '30rem',
}
}
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论