Object Position
Utilities for controlling how a replaced element’s content should be positioned within its container.
Class reference
Class | Properties |
---|---|
.object-bottom | object-position: bottom; |
.object-center | object-position: center; |
.object-left | object-position: left; |
.object-left-bottom | object-position: left bottom; |
.object-left-top | object-position: left top; |
.object-right | object-position: right; |
.object-right-bottom | object-position: right bottom; |
.object-right-top | object-position: right top; |
.object-top | object-position: top; |
Usage
Use the .object-{side}
utilities to specify how a replaced element’s content should be positioned within its container.
<img class="object-none object-left-top bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-top bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-right-top bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-left bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-center bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-right bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-left-bottom bg-gray-400 w-24 h-24" src="...">
<img class="object-none object-bottom bg-gray-400 w-24 h-24" src="...">
<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.
<img class="object-center sm:object-top md:object-right lg:object-bottom xl:object-left ..." src="...">
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.
- // tailwind.config.js
- module.exports = {
- theme: {
- objectPosition: {
- bottom: 'bottom',
- center: 'center',
- left: 'left',
- - 'left-bottom': 'left bottom',
- - 'left-top': 'left top',
- right: 'right',
- 'right-bottom': 'right bottom',
- 'right-top': 'right top',
- top: 'top',
- + 'center-bottom': 'center bottom'
- + 'center-top': 'center top',
- }
- }
- }
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:
- // tailwind.config.js
- module.exports = {
- variants: {
- // ...
- - objectPosition: ['responsive'],
- + objectPosition: ['responsive', 'hover', 'focus'],
- }
- }
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:
- // tailwind.config.js
- module.exports = {
- corePlugins: {
- // ...
- + objectPosition: false,
- }
- }