1. 布局
  2. 对象位置

Quick reference

Class
Properties
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;

基本用法

¥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.objectPositiontheme.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.

tailwind.config.js
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.