交互
用于抑制原生表单控件样式的工具类。
Class | Styles |
---|---|
appearance-none | appearance: none; |
appearance-auto | appearance: auto; |
使用 appearance-none
来重置元素上任何浏览器特定的样式:
<select> <option>Yes</option> <option>No</option> <option>Maybe</option></select><div class="grid"> <select class="col-start-1 row-start-1 appearance-none bg-gray-50 dark:bg-gray-800 ..."> <option>Yes</option> <option>No</option> <option>Maybe</option> </select> <svg class="pointer-events-none col-start-1 row-start-1 ..."> <!-- ... --> </svg></div>
该工具类常用于创建自定义表单组件时使用。
使用 appearance-auto
可以恢复元素在浏览器中的默认特定样式:
尝试在开发者工具中模拟 `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> 回退到默认外观</label><label> <div> <input type="checkbox" class="appearance-none ..." /> <svg class="invisible peer-checked:visible ..."> <!-- ... --> </svg> </div> 保持自定义外观</label>
这在某些无障碍模式下恢复为标准浏览器控件时非常有用。
Prefix an appearance
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<select class="appearance-auto md:appearance-none ..."> <!-- ... --></select>
Learn more about using variants in the variants documentation.