Object Position

Utilities for controlling how a replaced element’s content should be positioned within its container.

Class reference

ClassProperties
.object-bottomobject-position: bottom;
.object-centerobject-position: center;
.object-leftobject-position: left;
.object-left-bottomobject-position: left bottom;
.object-left-topobject-position: left top;
.object-rightobject-position: right;
.object-right-bottomobject-position: right bottom;
.object-right-topobject-position: right top;
.object-topobject-position: top;

Usage

Use the .object-{side} utilities to specify how a replaced element’s content should be positioned within its container.

Object Position - 图1

  1. <img class="object-none object-left-top bg-gray-400 w-24 h-24" src="...">
  2. <img class="object-none object-top bg-gray-400 w-24 h-24" src="...">
  3. <img class="object-none object-right-top bg-gray-400 w-24 h-24" src="...">
  4. <img class="object-none object-left bg-gray-400 w-24 h-24" src="...">
  5. <img class="object-none object-center bg-gray-400 w-24 h-24" src="...">
  6. <img class="object-none object-right bg-gray-400 w-24 h-24" src="...">
  7. <img class="object-none object-left-bottom bg-gray-400 w-24 h-24" src="...">
  8. <img class="object-none object-bottom bg-gray-400 w-24 h-24" src="...">
  9. <img class="object-none object-right-bottom bg-gray-400 w-24 h-24" src="...">

Responsive

To position an object only at a specific breakpoint, add a {screen}: prefix to any existing object position utility. For example, adding the class md:object-top to an element would apply the object-top utility at medium screen sizes and above.

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

  1. <img class="object-center sm:object-top md:object-right lg:object-bottom xl:object-left ..." src="...">

Object Position - 图2

Customizing

Object Positioning

By default Tailwind provides nine object position utilities. You can change, add, or remove these by editing the theme.objectPosition section of your Tailwind config.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. objectPosition: {
  5. bottom: 'bottom',
  6. center: 'center',
  7. left: 'left',
  8. - 'left-bottom': 'left bottom',
  9. - 'left-top': 'left top',
  10. right: 'right',
  11. 'right-bottom': 'right bottom',
  12. 'right-top': 'right top',
  13. top: 'top',
  14. + 'center-bottom': 'center bottom'
  15. + 'center-top': 'center top',
  16. }
  17. }
  18. }

Responsive and pseudo-class variants

By default, only responsive variants are generated for object position utilities.

You can control which variants are generated for the object position utilities by modifying the objectPosition 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. // ...
  5. - objectPosition: ['responsive'],
  6. + objectPosition: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

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

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