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-border background-origin: border-box;
bg-origin-padding background-origin: padding-box;
bg-origin-content background-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>

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

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