「及時」模式:全新世代的 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
屬性
bg-origin-borderbackground-origin: border-box;
bg-origin-paddingbackground-origin: padding-box;
bg-origin-contentbackground-origin: content-box;

用法

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>

響應式

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.

客製化

變化模式

默認情況下, 只有 響應式 的 background-origin 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 backgroundOrigin 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。

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

停用

如果你不打算在專案中使用 background-origin 功能,可以在你的設定檔裡的 corePlugins 屬性中將 backgroundOrigin 設定為 false 來停用功能:

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