- 入门
- 核心概念
- 定制
- 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
Customizing Spacing
Customizing the default spacing and sizing scale for your project.
Use the spacing
key in the theme
section of your tailwind.config.js
file to customize Tailwind’s default spacing/sizing scale.
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
spacing: {
'1': '8px',
'2': '12px',
'3': '16px',
'4': '24px',
'5': '32px',
'6': '48px',
}
}
}
By default the spacing scale is inherited by the padding
, margin
, width
, minWidth
, maxWidth
, height
, minHeight
, maxHeight
, gap
, inset
, space
, translate
, scrollMargin
, and scrollPadding
core plugins.
Extending the default spacing scale
As described in the theme documentation, if you’d like to extend the default spacing scale, you can do so using the theme.extend.spacing
section of your tailwind.config.js
file:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
spacing: {
'13': '3.25rem',
'15': '3.75rem',
'128': '32rem',
'144': '36rem',
}
}
}
}
This will generate classes like p-13
, m-15
, and h-128
in addition to all of Tailwind’s default spacing/sizing utilities.
Overriding the default spacing scale
As described in the theme documentation, if you’d like to override the default spacing scale, you can do so using the theme.spacing
section of your tailwind.config.js
file:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
spacing: {
sm: '8px',
md: '12px',
lg: '16px',
xl: '24px',
}
}
}
This will disable Tailwind’s default spacing scale and generate classes like p-sm
, m-md
, w-lg
, and h-xl
instead.
Default spacing scale
By default, Tailwind includes a generous and comprehensive numeric spacing scale. The values are proportional, so 16
is twice as much spacing as 8
for example. One spacing unit is equal to 0.25rem
, which translates to 4px
by default in common browsers.
Name | Size | Pixels | Preview |
---|---|---|---|
0 | 0px | 0px | |
px | 1px | 1px | |
0.5 | 0.125rem | 2px | |
1 | 0.25rem | 4px | |
1.5 | 0.375rem | 6px | |
2 | 0.5rem | 8px | |
2.5 | 0.625rem | 10px | |
3 | 0.75rem | 12px | |
3.5 | 0.875rem | 14px | |
4 | 1rem | 16px | |
5 | 1.25rem | 20px | |
6 | 1.5rem | 24px | |
7 | 1.75rem | 28px | |
8 | 2rem | 32px | |
9 | 2.25rem | 36px | |
10 | 2.5rem | 40px | |
11 | 2.75rem | 44px | |
12 | 3rem | 48px | |
14 | 3.5rem | 56px | |
16 | 4rem | 64px | |
20 | 5rem | 80px | |
24 | 6rem | 96px | |
28 | 7rem | 112px | |
32 | 8rem | 128px | |
36 | 9rem | 144px | |
40 | 10rem | 160px | |
44 | 11rem | 176px | |
48 | 12rem | 192px | |
52 | 13rem | 208px | |
56 | 14rem | 224px | |
60 | 15rem | 240px | |
64 | 16rem | 256px | |
72 | 18rem | 288px | |
80 | 20rem | 320px | |
96 | 24rem | 384px |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论