布局
用于控制替换元素的内容在其容器中的定位方式的工具。
¥Basic usage
¥Positioning a replaced element
使用 object-*
工具指定被替换元素的内容在其容器中的定位方式。
¥Use the object-*
utilities to specify how a replaced element’s content should be positioned within its container.
object-left-top
object-top
object-right-top
object-left
object-center
object-right
object-left-bottom
object-bottom
object-right-bottom
<img class="object-none object-left-top bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-top bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-right-top bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-left bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-center bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-right bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-left-bottom bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-bottom bg-yellow-300 w-24 h-24 ..." src="...">
<img class="object-none object-right-bottom bg-yellow-300 w-24 h-24 ..." src="...">
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:object-top
to only apply the object-top
utility on hover.
<img class="object-center hover:object-top" src="...">
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:object-top
to apply the object-top
utility at only medium screen sizes and above.
<img class="object-center md:object-top" src="...">
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
¥Using custom values
¥Customizing your theme
默认情况下,Tailwind 提供九个对象位置工具。你可以通过编辑 tailwind.config.js
文件中的 theme.objectPosition
或 theme.extend.objectPosition
来自定义这些值。
¥By default, Tailwind provides nine object position utilities. You can customize these values by editing theme.objectPosition
or theme.extend.objectPosition
in your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
objectPosition: {
'center-bottom': 'center bottom',
}
},
}
}
在 主题定制 文档中了解有关自定义默认主题的更多信息。
¥Learn more about customizing the default theme in the theme customization documentation.
¥Arbitrary values
If you need to use a one-off object-position
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<img class="object-[center_bottom]" src="...">
Learn more about arbitrary value support in the arbitrary values documentation.