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.

Background Origin - 图1

  1. <div class="bg-origin-border p-4 border-4 border-dashed ..." style="background-image: url(...)">
  2. 1
  3. </div>
  4. <div class="bg-origin-padding p-4 border-4 border-dashed ..." style="background-image: url(...)">
  5. 2
  6. </div>
  7. <div class="bg-origin-content p-4 border-4 border-dashed ..." style="background-image: url(...)">
  8. 3
  9. </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.

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

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

Customizing

Variants

By default, only responsive variants are generated for background-origin utilities.

You can control which variants are generated for the background-origin utilities by modifying the backgroundOrigin property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. extend: {
  5. // ...
  6. + backgroundOrigin: ['hover', 'focus'],
  7. }
  8. }
  9. }

Disabling

If you don’t plan to use the background-origin utilities in your project, you can disable them entirely by setting the backgroundOrigin property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + backgroundOrigin: false,
  6. }
  7. }

←Background Opacity Background Position→

Edit this page on GitHub