1. 背景
  2. 背景重复

Quick reference

属性
bg-repeatbackground-repeat: repeat;
bg-no-repeatbackground-repeat: no-repeat;
bg-repeat-xbackground-repeat: repeat-x;
bg-repeat-ybackground-repeat: repeat-y;
bg-repeat-roundbackground-repeat: round;
bg-repeat-spacebackground-repeat: space;

基本用法(Basic usage)

重复(Repeat)

使用 bg-repeat 在垂直和水平方向上重复背景图片。

🌐 Use bg-repeat to repeat the background image both vertically and horizontally.

<div class="bg-repeat ..." style="background-image: url(...)"></div>

不重复(No Repeat)

当你不想重复背景图片时,使用 bg-no-repeat

🌐 Use bg-no-repeat when you don’t want to repeat the background image.

<div class="bg-no-repeat bg-center ..." style="background-image: url(...)"></div>

水平重复(Repeat Horizontally)

使用 bg-repeat-x 仅在水平方向重复背景图片。

🌐 Use bg-repeat-x to repeat the background image only horizontally.

<div class="bg-repeat-x bg-center ..." style="background-image: url(...)"></div>

垂直重复(Repeat Vertically)

使用 bg-repeat-y 仅垂直重复背景图片。

🌐 Use bg-repeat-y to repeat the background image only vertically.

<div class="bg-repeat-y bg-center ..." style="background-image: url(...)"></div>

有条件申请

悬停、聚焦及其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:bg-repeat-x 仅在 hover 时应用 bg-repeat-x 工具。

<div class="bg-repeat hover:bg-repeat-x">
  <!-- ... -->
</div>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:bg-repeat-x 仅在中等屏幕尺寸及以上时应用 bg-repeat-x 工具。

<div class="bg-repeat md:bg-repeat-x">
  <!-- ... -->
</div>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。