1. 交互
  2. 外貌

Quick reference

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

尝试模拟“forced-colors: active” 在你的开发者工具中查看差异

<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 lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:appearance-none to only apply the appearance-none utility on hover.

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

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:appearance-none to apply the appearance-none utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.