Just-in-Time: The Next Generation of Tailwind CSS
Tailwind CSS on GitHub

Background Origin

Tailwind CSS version
v2.2+

Utilities for controlling how an element's background is positioned relative to borders, padding, and content.

Default class reference

Class
Properties
bg-origin-borderbackground-origin: border-box;
bg-origin-paddingbackground-origin: padding-box;
bg-origin-contentbackground-origin: content-box;

Usage

Use bg-origin-border, bg-origin-padding, and bg-origin-content to control where an element’s background is rendered.

1
2
3
<div class="bg-origin-border p-4 border-4 border-dashed ..." style="background-image: url(...)">
  1
</div>

<div class="bg-origin-padding p-4 border-4 border-dashed ..." style="background-image: url(...)">
  2
</div>

<div class="bg-origin-content p-4 border-4 border-dashed ..." style="background-image: url(...)">
  3
</div>

Responsive

To control the background-origin property at a specific breakpoint, add a {screen}: prefix to any existing background-origin utility. For example, use md:bg-origin-padding to apply the bg-origin-padding utility at only medium screen sizes and above.

<div class="bg-origin-border md:bg-origin-padding ...">
  <!-- ... -->
</div>

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Customizing

Variants

默认情况下, 针对 background-origin 功能类,只生成 responsive 变体。

您可以通过修改您的 tailwind.config.js 文件中的 variants 部分中的 backgroundOrigin 属性来控制为 background-origin 功能生成哪些变体。

例如,这个配置将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       backgroundOrigin: ['hover', 'focus'],
      }
    }
  }

Disabling

如果您不打算在您的项目中使用 background-origin 功能,您可以通过在配置文件的 corePlugins 部分将 backgroundOrigin 属性设置为 false 来完全禁用它们:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     backgroundOrigin: false,
    }
  }