1. 间距
  2. 内边距

间距

padding

用于控制元素内边距的工具类。

ClassStyles
p-<number>
padding: calc(var(--spacing) * <number>);
p-px
padding: 1px;
p-(<custom-property>)
padding: var(<custom-property>);
p-[<value>]
padding: <value>;
px-<number>
padding-inline: calc(var(--spacing) * <number>);
px-px
padding-inline: 1px;
px-(<custom-property>)
padding-inline: var(<custom-property>);
px-[<value>]
padding-inline: <value>;
py-<number>
padding-block: calc(var(--spacing) * <number>);
py-px
padding-block: 1px;

示例

基本示例

使用类似 p-4p-8p-<number> 工具类来控制元素四周的内边距:

p-8
<div class="p-8 ...">p-8</div>

添加单边内边距

使用 pt-<number>pr-<number>pb-<number>pl-<number> 工具类,比如 pt-6pr-4,来控制元素某一侧的内边距:

pt-6
pr-4
pb-8
pl-2
<div class="pt-6 ...">pt-6</div><div class="pr-4 ...">pr-4</div><div class="pb-8 ...">pb-8</div><div class="pl-2 ...">pl-2</div>

添加水平内边距

使用类似 px-4px-8px-<number> 工具类来控制元素的水平内边距:

px-8
<div class="px-8 ...">px-8</div>

添加垂直内边距

使用类似 py-4py-8py-<number> 工具类来控制元素的垂直内边距:

py-8
<div class="py-8 ...">py-8</div>

使用逻辑属性

使用 ps-<number>pe-<number> 工具类,比如 ps-4pe-8,设置 padding-inline-startpadding-inline-end 逻辑属性,根据文本方向映射到左侧或右侧:

从左到右

ps-8
pe-8

从右到左

ps-8
pe-8
<div>  <div dir="ltr">    <div class="ps-8 ...">ps-8</div>    <div class="pe-8 ...">pe-8</div>  </div>  <div dir="rtl">    <div class="ps-8 ...">ps-8</div>    <div class="pe-8 ...">pe-8</div>  </div></div>

为了获得更多控制,您还可以使用 LTR 和 RTL 修饰符 来根据当前文本方向有条件地应用特定样式。

使用自定义值

Use utilities like p-[<value>],px-[<value>], and pb-[<value>] to set the 内边距 based on a completely custom value:

<div class="p-[5px] ...">  <!-- ... --></div>

For CSS variables, you can also use the p-(<custom-property>) syntax:

<div class="p-(--my-padding) ...">  <!-- ... --></div>

This is just a shorthand for p-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a 内边距 utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<div class="py-4 md:py-8 ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

自定义主题

The p-<number>,px-<number>,py-<number>,ps-<number>,pe-<number>,pt-<number>,pr-<number>,pb-<number>, and pl-<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.