Tailwindcss 常见用法
全文共 317 字预计阅读 2 分钟
盒模型相关
- 宽度和高度
width和heightw-<number>表示宽度,h-<number>表示高度(会根据 HTML 根元素的 font-size 计算实际值)。w-<fraction>fraction 表示分数,比如 1 / 2 = 50% 。- 也可以用
w-2xs/xs/sm/md/lg/xl/2xl这种表示方法。 w-auto/full/screen/min/max/fit这些是特殊一点的。w-[<value>]可以自定义值。
- 尺寸
size-是同时设置width和height。 - 最小最大宽度高度
min-width和max-widthmin-w-<>类似上面的用法,用于设定最小和最大值。 - 背景
bg-<>背景颜色。 - 内外边距
padding和margin- 用
p-<>和m-<>表示内外边距(上下左右都是)。 - 如果单独调左右用
px-<>,上下用py-<>。 - 左
l,右r,上t,下b,起始s,结束e。
- 用
- 边框
border-<>边框可以是长度或颜色。rounded-<>圆角shadow-<>阴影,长度和颜色。
- 位置
absolute表示绝对位置。top-<>距离上面,同样的left-<>...
文字相关
- 颜色、大小、对齐
text-<number>大小。text-<color>颜色。text-<center/left/right>对齐。
- 行距
leading-<number>行距。 - 粗细
font-<bold/light...> - 字体
font-<sans/serif>
flex / grid 相关
flex- 相当于
display: flex默认是横向。 flex-row横向,flex-col纵向,flex-row-reverse反向。
- 相当于
hidden隐藏,相当于display: noneflex-<wrap/nowarp>溢出。basis-<number>默认值,配合grow进行放大(填充没用的空间)shrink缩小 。gridgrid-cols-<number>有多少列,grid-rows-<number>多少行。
justify-<>主轴排布,content-<>纵轴排布。justify-item-<>、items-<>。gap调整间距。
封装
在 Vue 中使用示例如下。
<template>
<h1 class="xxx">Hello world!</h1>
</template>
<style>
@reference "../../app.css";
.xxx {
@apply text-2xl font-bold text-red-500;
}
</style>