1. 交互
  2. 外貌

Quick reference

属性
appearance-noneappearance: none;
appearance-autoappearance: auto;

基本用法(Basic usage)

删除默认元素外观(Removing default element appearance)

使用 appearance-none 重置元素上的任何浏览器特定样式。这个工具通常在创建自定义表单组件时使用。

🌐 Use appearance-none to reset any browser specific styling on an element. This utility is often used when creating custom form components.

Default browser styles applied
Remove default browser styles
<select>
  <option>Yes</option>
  <option>No</option>
  <option>Maybe</option>
</select>

<div class="grid">
  <select class="appearance-none row-start-1 col-start-1 bg-slate-50 dark:bg-slate-800 ...">
    <option>Yes</option>
    <option>No</option>
    <option>Maybe</option>
  </select>
  <svg class="pointer-events-none row-start-1 col-start-1 ...">
    <!-- ... -->
  </svg>
</div>

恢复默认元素外观(Restoring the default element appearance)

使用 appearance-auto 可以恢复元素的默认浏览器特定样式。这在某些无障碍模式下恢复标准浏览器控件时非常有用。

🌐 Use appearance-auto to restore the default browser specific styling on an element. This is useful for reverting to the standard browser controls in certain accessibility modes.

Try emulating `forced-colors: active` in your developer tools to see the difference

<label>
  <div>
    <input type="checkbox" class="appearance-none forced-colors:appearance-auto ..." />
    <svg class="invisible peer-checked:visible forced-colors:hidden ..." >
      <!-- ... -->
    </svg>
  </div>
  Falls back to default appearance
</label>

<label>
  <div>
    <input type="checkbox" class="appearance-none ..." />
    <svg class="invisible peer-checked:visible ...">
      <!-- ... -->
    </svg>
  </div>
  Keeps custom appearance
</label>

有条件申请

悬停、聚焦及其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:appearance-none 仅在 hover 时应用 appearance-none 工具。

<div class="appearance-auto hover:appearance-none">
  <!-- ... -->
</div>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:appearance-none 仅在中等屏幕尺寸及以上时应用 appearance-none 工具。

<div class="appearance-auto md:appearance-none">
  <!-- ... -->
</div>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。