
Tailwind CSS常用样式记录
Tailwind CSS 提供了大量的实用工具类来实现常见的 CSS 样式。以下是 100 种常见的 CSS 样式及其在 Tailwind 中的写法:
-
Margin
margin: 0;->m-0margin-top: 1rem;->mt-4margin-right: 2rem;->mr-8
-
Padding
padding: 0;->p-0padding-top: 1rem;->pt-4padding-right: 2rem;->pr-8
-
Width
width: 100%;->w-fullwidth: 50%;->w-1/2width: calc(100% - 2rem);->w-[calc(100%-2rem)]
-
Height
height: 100%;->h-fullheight: 50vh;->h-1/2height: calc(100vh - 4rem);->h-[calc(100vh-4rem)]
-
Text Align
text-align: left;->text-lefttext-align: center;->text-centertext-align: right;->text-right
-
Font Size
font-size: 1rem;->text-basefont-size: 2rem;->text-2xlfont-size: 3rem;->text-3xl
-
Font Weight
font-weight: 400;->font-normalfont-weight: 700;->font-boldfont-weight: 900;->font-black
-
Line Height
line-height: 1;->leading-noneline-height: 1.5;->leading-snugline-height: 2;->leading-loose
-
Background Color
background-color: #fff;->bg-whitebackground-color: #000;->bg-blackbackground-color: #f00;->bg-red-500
-
Text Color
color: #fff;->text-whitecolor: #000;->text-blackcolor: #f00;->text-red-500
-
Border Width
border-width: 1px;->borderborder-width: 2px;->border-2border-width: 0;->border-0
-
Border Color
border-color: #fff;->border-whiteborder-color: #000;->border-blackborder-color: #f00;->border-red-500
-
Border Radius
border-radius: 0;->rounded-noneborder-radius: 0.25rem;->roundedborder-radius: 0.5rem;->rounded-md
-
Display
display: block;->blockdisplay: inline-block;->inline-blockdisplay: flex;->flex
-
Flex Direction
flex-direction: row;->flex-rowflex-direction: column;->flex-colflex-direction: row-reverse;->flex-row-reverse
-
Justify Content
justify-content: flex-start;->justify-startjustify-content: center;->justify-centerjustify-content: space-between;->justify-between
-
Align Items
align-items: stretch;->items-stretchalign-items: center;->items-centeralign-items: flex-start;->items-start
-
Position
position: static;->staticposition: relative;->relativeposition: absolute;->absolute
-
Top, Right, Bottom, Left
top: 0;->top-0right: 0;->right-0bottom: 0;->bottom-0left: 0;->left-0
-
Overflow
overflow: visible;->overflow-visibleoverflow: hidden;->overflow-hiddenoverflow: scroll;->overflow-scroll
-
Visibility
visibility: visible;->visiblevisibility: hidden;->invisible
-
Z-Index
z-index: 0;->z-0z-index: 10;->z-10z-index: 50;->z-50
-
Opacity
opacity: 1;->opacity-100opacity: 0.5;->opacity-50opacity: 0;->opacity-0
-
Box Shadow
box-shadow: none;->shadow-nonebox-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);->shadow-smbox-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);->shadow-md
-
Cursor
cursor: pointer;->cursor-pointercursor: not-allowed;->cursor-not-allowedcursor: text;->cursor-text
-
Text Transform
text-transform: uppercase;->uppercasetext-transform: lowercase;->lowercasetext-transform: capitalize;->capitalize
-
Letter Spacing
letter-spacing: normal;->tracking-normalletter-spacing: 0.1em;->tracking-wideletter-spacing: -0.05em;->tracking-tight
-
List Style Type
list-style-type: none;->list-nonelist-style-type: disc;->list-disclist-style-type: decimal;->list-decimal
-
Text Decoration
text-decoration: underline;->underlinetext-decoration: line-through;->line-throughtext-decoration: none;->no-underline
-
Font Style
font-style: italic;->italicfont-style: normal;->not-italic
-
Background Size
background-size: auto;->bg-autobackground-size: cover;->bg-coverbackground-size: contain;->bg-contain
-
Background Position
background-position: center;->bg-centerbackground-position: top;->bg-topbackground-position: bottom;->bg-bottom
-
Background Repeat
background-repeat: repeat;->bg-repeatbackground-repeat: no-repeat;->bg-no-repeatbackground-repeat: repeat-x;->bg-repeat-x
-
Background Attachment
background-attachment: scroll;->bg-scrollbackground-attachment: fixed;->bg-fixedbackground-attachment: local;->bg-local
-
Border Style
border-style: solid;->border-solidborder-style: dashed;->border-dashedborder-style: dotted;->border-dotted
-
Float
float: left;->float-leftfloat: right;->float-rightfloat: none;->float-none
-
Clear
clear: left;->clear-leftclear: right;->clear-rightclear: both;->clear-both
-
Object Fit
object-fit: contain;->object-containobject-fit: cover;->object-coverobject-fit: fill;->object-fill
-
Object Position
object-position: center;->object-centerobject-position: top;->object-topobject-position: bottom;->object-bottom
-
Overflow X
overflow-x: visible;->overflow-x-visibleoverflow-x: hidden;->overflow-x-hiddenoverflow-x: scroll;->overflow-x-scroll
-
Overflow Y
overflow-y: visible;->overflow-y-visibleoverflow-y: hidden;->overflow-y-hiddenoverflow-y: scroll;->overflow-y-scroll
-
Order
order: 1;->order-1order: 2;->order-2order: -1;->order-first
-
Flex Wrap
flex-wrap: nowrap;->flex-nowrapflex-wrap: wrap;->flex-wrapflex-wrap: wrap-reverse;->flex-wrap-reverse
-
Flex Grow
flex-grow: 0;->flex-grow-0flex-grow: 1;->flex-grow
-
Flex Shrink
flex-shrink: 0;->flex-shrink-0flex-shrink: 1;->flex-shrink
-
Grid Template Columns
grid-template-columns: none;->grid-cols-nonegrid-template-columns: repeat(3, minmax(0, 1fr));->grid-cols-3grid-template-columns: 1fr 2fr;->grid-cols-[1fr_2fr]
-
Grid Column Start / End
grid-column: 1 / span 2;->col-span-2grid-column: auto / auto;->col-auto
-
Grid Template Rows
grid-template-rows: none;->grid-rows-nonegrid-template-rows: repeat(3, minmax(0, 1fr));->grid-rows-3grid-template-rows: 1fr 2fr;->grid-rows-[1fr_2fr]
-
Grid Row Start / End
grid-row: 1 / span 2;->row-span-2grid-row: auto / auto;->row-auto
-
Grid Gap
gap: 0;->gap-0gap: 1rem;->gap-4gap: 2rem;->gap-8
-
Grid Column Gap
column-gap: 0;->col-gap-0column-gap: 1rem;->col-gap-4column-gap: 2rem;->col-gap-8
-
Grid Row Gap
row-gap: 0;->row-gap-0row-gap: 1rem;->row-gap-4row-gap: 2rem;->row-gap-8
-
Place Content
place-content: center;->place-content-centerplace-content: start;->place-content-startplace-content: end;->place-content-end
-
Place Items
place-items: center;->place-items-centerplace-items: start;->place-items-startplace-items: end;->place-items-end
-
Place Self
place-self: auto;->place-self-autoplace-self: start;->place-self-startplace-self: end;->place-self-end
-
Top/Right/Bottom/Left
top: 1rem;->top-4right: 1rem;->right-4bottom: 1rem;->bottom-4left: 1rem;->left-4
-
Min Width
min-width: 0;->min-w-0min-width: 100%;->min-w-full
-
Min Height
min-height: 0;->min-h-0min-height: 100vh;->min-h-screen
-
Max Width
max-width: none;->max-w-nonemax-width: 100%;->max-w-fullmax-width: 50rem;->max-w-2xl
-
Max Height
max-height: none;->max-h-nonemax-height: 100vh;->max-h-screen
-
Pointer Events
pointer-events: none;->pointer-events-nonepointer-events: auto;->pointer-events-auto
-
Resize
resize: none;->resize-noneresize: both;->resizeresize: horizontal;->resize-xresize: vertical;->resize-y
-
Stroke
stroke: currentColor;->stroke-current
-
Stroke Width
stroke-width: 0;->stroke-0stroke-width: 1;->stroke-1stroke-width: 2;->stroke-2
-
Fill
fill: none;->fill-nonefill: currentColor;->fill-current
-
Table Layout
table-layout: auto;->table-autotable-layout: fixed;->table-fixed
-
Text Overflow
text-overflow: ellipsis;->text-ellipsistext-overflow: clip;->text-clip
-
Transform
transform: scale(1);->transformtransform: scale(1.5);->scale-150transform: rotate(45deg);->rotate-45
-
Transform Origin
transform-origin: center;->origin-centertransform-origin: top;->origin-toptransform-origin: bottom;->origin-bottom
-
Translate
translate-x: 0;->translate-x-0translate-x: 50%;->translate-x-1/2translate-y: 0;->translate-y-0translate-y: 50%;->translate-y-1/2
-
Scale
scale: 1;->scale-100scale: 1.5;->scale-150scale: 0.5;->scale-50
-
Rotate
rotate: 0deg;->rotate-0rotate: 45deg;->rotate-45rotate: -45deg;->-rotate-45
-
Skew
skew-x: 0deg;->skew-x-0skew-x: 10deg;->skew-x-10skew-y: 0deg;->skew-y-0skew-y: 10deg;->skew-y-10
-
Transition Property
transition-property: none;->transition-nonetransition-property: all;->transition-alltransition-property: opacity;->transition-opacity
-
Transition Duration
transition-duration: 150ms;->duration-150transition-duration: 300ms;->duration-300
-
Transition Timing Function
transition-timing-function: ease;->easetransition-timing-function: linear;->lineartransition-timing-function: ease-in;->ease-in
-
Transition Delay
transition-delay: 75ms;->delay-75transition-delay: 150ms;->delay-150
-
Animation
animation: none;->animate-noneanimation: spin;->animate-spinanimation: ping;->animate-ping
-
List Style Position
list-style-position: inside;->list-insidelist-style-position: outside;-> `list-out
-
Backdrop Filter
backdrop-filter: none;->backdrop-filter-nonebackdrop-filter: blur(10px);->backdrop-blur-[10px]backdrop-filter: contrast(200%);->backdrop-contrast-[200%]
-
Box Sizing
box-sizing: border-box;->box-borderbox-sizing: content-box;->box-content
-
Caret Color
caret-color: #000;->caret-blackcaret-color: #fff;->caret-white
-
Grid Auto Columns
grid-auto-columns: auto;->auto-cols-autogrid-auto-columns: minmax(0, 1fr);->auto-cols-min
-
Grid Auto Rows
grid-auto-rows: auto;->auto-rows-autogrid-auto-rows: minmax(0, 1fr);->auto-rows-min
-
Justify Items
justify-items: start;->justify-items-startjustify-items: center;->justify-items-centerjustify-items: end;->justify-items-end
-
Justify Self
justify-self: start;->justify-self-startjustify-self: center;->justify-self-centerjustify-self: end;->justify-self-end
-
Object Fit
object-fit: contain;->object-containobject-fit: cover;->object-coverobject-fit: fill;->object-fill
-
Outline
outline: 2px solid transparent;->outline-noneoutline: 2px dashed #000;->outline-dashedoutline-offset: 2px;->outline-offset-2
-
Place Content
place-content: center;->place-content-centerplace-content: start;->place-content-startplace-content: end;->place-content-end
-
Scroll Behavior
scroll-behavior: auto;->scroll-autoscroll-behavior: smooth;->scroll-smooth
-
Scroll Snap Align
scroll-snap-align: start;->snap-startscroll-snap-align: center;->snap-centerscroll-snap-align: end;->snap-end
-
Scroll Snap Stop
scroll-snap-stop: normal;->snap-normalscroll-snap-stop: always;->snap-always
-
Scroll Snap Type
scroll-snap-type: none;->snap-nonescroll-snap-type: x mandatory;->snap-xscroll-snap-type: y mandatory;->snap-y
-
Touch Action
touch-action: auto;->touch-autotouch-action: none;->touch-nonetouch-action: manipulation;->touch-manipulation
-
User Select
user-select: none;->select-noneuser-select: text;->select-textuser-select: all;->select-all
-
Vertical Align
vertical-align: baseline;->align-baselinevertical-align: top;->align-topvertical-align: middle;->align-middle
-
Visibility
visibility: visible;->visiblevisibility: hidden;->invisible
-
Whitespace
white-space: normal;->whitespace-normalwhite-space: nowrap;->whitespace-nowrapwhite-space: pre;->whitespace-pre
-
Word Break
word-break: break-all;->break-allword-break: keep-all;->break-keepword-break: break-word;->break-word
-
Writing Mode -
writing-mode: horizontal-tb;->writing-horizontal-writing-mode: vertical-rl;->writing-vertical-writing-mode: vertical-lr;->writing-vertical-lr
这些 Tailwind CSS 类可以帮助你快速地应用常见的 CSS 样式,而不需要编写传统的 CSS 代码。通过这些实用工具类,你可以大大提高开发效率,并且保持代码的一致性和可维护性。
Likes


