Backgrounds

Background Origin

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

Quick reference

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

Basic usage

Setting the background origin

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

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:bg-origin-padding to only apply the bg-origin-padding utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. 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>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.