HTML 5 <input type"color" /> 设备不同

HTML 5 <input type"color" /> different on devices

我使用的是标准 input 元素,它在移动设备和浏览器中的呈现方式不同

<input type="color" />

浏览器:

手机:

为什么会这样?我更喜欢浏览器版本,所以如果我可以强制浏览器渲染所有内容那就太好了

Why is this the case?

他们在 运行 所在的平台上使用标准颜色选择器小部件。

应用程序之间 UI 的一致性是一种美德。

I can force browser rendering

你不能。

最接近的方法是从头开始实现您自己的颜色选择器,或者使用完全绕过本机控件的库。

来自 <input type="color"> MDN Web Docs:

The element's presentation may vary substantially from one browser and/or platform to another—it might be a simple textual input that automatically validates to ensure that the color information is entered in the proper format, or a platform-standard color picker, or some kind of custom color picker window.

遗憾的是,无法'force'特定的演示文稿。


'Appearance variantions' 中,您会找到一些在不同设备上的示例,例如 macOS 系统颜色选择器。

<input type="color" />样式取决于系统默认样式。
如果您想要统一的风格,请尝试使用外部库,例如 Simonwep pickr