- 入门
- 核心概念
- 定制
- 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
Preflight
An opinionated set of base styles for Tailwind projects.
Overview
Built on top of modern-normalize, Preflight is a set of base styles for Tailwind projects that are designed to smooth over cross-browser inconsistencies and make it easier for you to work within the constraints of your design system.
Tailwind automatically injects these styles when you include @tailwind base
in your CSS:
@tailwind base; /* Preflight will be injected here */
@tailwind components;
@tailwind utilities;
While most of the styles in Preflight are meant to go unnoticed — they simply make things behave more like you’d expect them to — some are more opinionated and can be surprising when you first encounter them.
For a complete reference of all the styles applied by Preflight, see the stylesheet.
Default margins are removed
Preflight removes all of the default margins from elements like headings, blockquotes, paragraphs, etc.
blockquote,
dl,
dd,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
figure,
p,
pre {
margin: 0;
}
This makes it harder to accidentally rely on margin values applied by the user-agent stylesheet that are not part of your spacing scale.
Headings are unstyled
All heading elements are completely unstyled by default, and have the same font-size and font-weight as normal text.
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: inherit;
font-weight: inherit;
}
The reason for this is two-fold:
- It helps you avoid accidentally deviating from your type scale. By default, browsers assign sizes to headings that don’t exist in Tailwind’s default type scale, and aren’t guaranteed to exist in your own type scale.
- In UI development, headings should often be visually de-emphasized. Making headings unstyled by default means any styling you apply to headings happens consciously and deliberately.
You can always add default header styles to your project by adding your own base styles.
If you’d like to selectively introduce sensible default heading styles into article-style parts of a page, we recommend the @tailwindcss/typography plugin.
Lists are unstyled
Ordered and unordered lists are unstyled by default, with no bullets/numbers and no margin or padding.
ol,
ul {
list-style: none;
margin: 0;
padding: 0;
}
If you’d like to style a list, you can do so using the list-style-type and list-style-position utilities:
<ul class="list-disc list-inside">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
You can always add default list styles to your project by adding your own base styles.
If you’d like to selectively introduce default list styles into article-style parts of a page, we recommend the @tailwindcss/typography plugin.
Accessibility considerations
Unstyled lists are not announced as lists by VoiceOver. If your content is truly a list but you would like to keep it unstyled, add a “list” role to the element:
<ul role="list">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Images are block-level
Images and other replaced elements (like svg
, video
, canvas
, and others) are display: block
by default.
img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
display: block;
vertical-align: middle;
}
This helps to avoid unexpected alignment issues that you often run into using the browser default of display: inline
.
If you ever need to make one of these elements inline
instead of block
, simply use the inline
utility:
<img class="inline" src="..." alt="...">
Images are constrained to the parent width
Images and videos are constrained to the parent width in a way that preserves their intrinsic aspect ratio.
img,
video {
max-width: 100%;
height: auto;
}
This prevents them from overflowing their containers and makes them responsive by default. If you ever need to override this behavior, use the max-w-none
utility:
<img class="max-w-none" src="..." alt="...">
Border styles are reset globally
In order to make it easy to add a border by simply adding the border
class, Tailwind overrides the default border styles for all elements with the following rules:
*,
::before,
::after {
border-width: 0;
border-style: solid;
border-color: theme('borderColor.DEFAULT', currentColor);
}
Since the border
class only sets the border-width
property, this reset ensures that adding that class always adds a solid 1px border using your configured default border color.
This can cause some unexpected results when integrating certain third-party libraries, like Google maps for example.
When you run into situations like this, you can work around them by overriding the Preflight styles with your own custom CSS:
.google-map * {
border-style: none;
}
Extending Preflight
If you’d like to add your own base styles on top of Preflight, simply add them to your CSS using the @layer base
directive:
@tailwind base;
@layer base {
h1 {
@apply text-2xl;
}
h2 {
@apply text-xl;
}
h3 {
@apply text-lg;
}
a {
@apply text-blue-600 underline;
}
}
@tailwind components;
@tailwind utilities;
Learn more in the adding base styles documentation.
Disabling Preflight
If you’d like to completely disable Preflight — perhaps because you’re integrating Tailwind into an existing project or because you’d like to provide your own base styles — all you need to do is set preflight
to false
in the corePlugins
section of your tailwind.config.js
file:
module.exports = {
corePlugins: {
preflight: false,
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论