这里只展示常用class,详细的class及用法见官网文档
布局相关
Box Sizing
| Class | Properties |
|---|---|
| box-border | box-sizing: border-box; |
| box-content | box-sizing: content-box; |
<div class="box-border h-32 w-32 p-4 border-4 ..."><!-- ... --></div><div class="box-content h-32 w-32 p-4 border-4 ..."><!-- ... --></div>
Display
控制元素显示类型的功能类
| Class | Properties |
|---|---|
| block | display: block; |
| inline-block | display: inline-block; |
| inline | display: inline; |
| flex | display: flex; |
| inline-flex | display: inline-flex; |
| table | display: table; |
| inline-table | display: inline-table; |
| table-caption | display: table-caption; |
| table-cell | display: table-cell; |
| table-column | display: table-column; |
| table-column-group | display: table-column-group; |
| table-footer-group | display: table-footer-group; |
| table-header-group | display: table-header-group; |
| table-row-group | display: table-row-group; |
| table-row | display: table-row; |
| flow-root | display: flow-root; |
| grid | display: grid; |
| inline-grid | display: inline-grid; |
| contents | display: contents; |
| list-item | display: list-item; |
| hidden | display: none; |
注意:display:none; 为 hidden
//display:block<div class="space-y-4 ..."><span class="block ...">1</span></div>//display:inline-block<div class="space-x-4 ..."><div class="inline-block ...">1</div></div>//display:inline<div><div class="inline ...">1</div></div>//display:none<div><div class="hidden ...">1</div><div>2</div></div>
flex
grid
浮动float与清除浮动
控制元素周围内容浮动
浮动
| Class | Properties |
|---|---|
| float-right | float: right; |
| float-left | float: left; |
| float-none | float: none; |
清除浮动
| Class | Properties |
|---|---|
| clear-left | clear: left; |
| clear-right | clear: right; |
| clear-both | clear: both; |
| clear-none | clear: none; |
Object Fit
object-fit 一般用于 img 和 video 标签,一般可以对这些元素进行保留原始比例的剪切、缩放或者直接进行拉伸等。
| Class | Properties |
|---|---|
| object-contain | object-fit: contain; |
| object-cover | object-fit: cover; |
| object-fill | object-fit: fill; |
| object-none | object-fit: none; |
| object-scale-down | object-fit: scale-down; |
<div class="bg-rose-300 ...">//使用 .object-contain 调整元素内容的大小,使其保持在容器内。<img class="object-contain h-48 w-full ...">//使用 .object-cover 调整元素内容的大小以覆盖其容器。<img class="object-cover h-48 w-full ...">//使用 .object-fill 拉伸元素的内容以适应其容器。<img class="object-fill h-48 w-full ...">//使用 .object-none 以原始大小显示元素的内容,忽略容器大小。<img class="object-none h-48 w-full ...">//以原始大小显示元素的内容,但必要时使用 .object-scale-down 将其缩小以适应其容器。<img class="object-scale-down h-48 w-full ..."></div>
Object Position
object-position 属性一般与 object-fit一起使用,用来设置元素的位置。
object-position 一般用于 img 和 video 标签。
| Class | Properties |
|---|---|
| object-bottom | object-position: bottom; |
| object-center | object-position: center; |
| object-left | object-position: left; |
| object-left-bottom | object-position: left bottom; |
| object-left-top | object-position: left top; |
| object-right | object-position: right; |
| object-right-bottom | object-position: right bottom; |
| object-right-top | object-position: right top; |
| object-top | object-position: top; |
使用 object-{side} 功能来指定可替换元素的内容在其容器中的位置。
溢出 overflow
用于控制元素如何处理超出容器的内容的功能类。
| Class | Properties |
|---|---|
| overflow-auto | overflow: auto; |
| overflow-hidden | overflow: hidden; |
| overflow-visible | overflow: visible; |
| overflow-scroll | overflow: scroll; |
| overflow-x-auto | overflow-x: auto; |
| overflow-y-auto | overflow-y: auto; |
| overflow-x-hidden | overflow-x: hidden; |
| overflow-y-hidden | overflow-y: hidden; |
| overflow-x-visible | overflow-x: visible; |
| overflow-y-visible | overflow-y: visible; |
| overflow-x-scroll | overflow-x: scroll; |
| overflow-y-scroll | overflow-y: scroll; |
定位 position
用于控制元素在DOM中的位置的功能类。
| Class | Properties |
|---|---|
| static | position: static; |
| fixed | position: fixed; |
| absolute | position: absolute; |
| relative | position: relative; |
| sticky | position: sticky; |
用于控制定位元素的位置的功能类。
使用 {top|right|bottom|left|inset}-0 功能类,将绝对定位的元素锚定在最近定位的父元素的任何边缘上。
| Class | Properties |
|---|---|
| top-1.5 | top: 0.375rem; |
| -top-1.5 | top: -0.375rem; |
| top-1/2 | top: 50%; |
| top-full | top: 100%; |
<div class="relative h-32 w-32 ..."><div class="absolute top-0 right-0 h-16 w-16 ...">7</div></div>
可见 visiable
| Class | Properties |
|---|---|
| visible | visibility: visible; |
| invisible | visibility: hidden; |
注意:visibility: hidden; 为 invisible
Z-Index
用于控制元素的堆栈顺序的功能类。
| Class | Properties |
|---|---|
| z-0 | z-index: 0; |
| z-10 | z-index: 10; |
| z-20 | z-index: 20; |
| z-30 | z-index: 30; |
| z-40 | z-index: 40; |
| z-50 | z-index: 50; |
| z-auto | z-index: auto; |
尺寸相关
文字排版相关
背景相关
边框相关
过渡和动画相关
transform
translate
scale
rotate
skew
